From 6d4f5c68dfca7c74f3ea2933069b4a3f225f4ab3 Mon Sep 17 00:00:00 2001 From: Samuel Andersson Date: Fri, 13 Sep 2024 12:03:00 +0200 Subject: [PATCH 1/3] fix: compile types --- http/index.d.ts | 22 +++++++++++----------- package.json | 1 + src/http/create_cookie_agent.ts | 2 +- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/http/index.d.ts b/http/index.d.ts index 7ce8e37f..1d61d418 100644 --- a/http/index.d.ts +++ b/http/index.d.ts @@ -1,5 +1,5 @@ -import type http from 'node:http'; -import type https from 'node:https'; +import type { Agent as HttpAgent, AgentOptions as HttpAgentOptions } from 'node:http'; +import type { Agent as HttpsAgent, AgentOptions as HttpsAgentOptions } from 'node:https'; import type { CookieJar } from 'tough-cookie'; @@ -11,19 +11,19 @@ export type CookieAgentOptions = { cookies?: CookieOptions | undefined; }; -type CookieAgent = BaseAgent; +type CookieAgent = BaseAgent; -type WithCookieAgentOptions = T extends http.AgentOptions ? T & CookieAgentOptions : T; -type ConstructorParams = { +type WithCookieAgentOptions = T extends HttpAgentOptions ? T & CookieAgentOptions : T; +type ConstructorParams = { [Index in keyof Params]: WithCookieAgentOptions; -} & { length: Params['length'] }; +}; -export function createCookieAgent( +export function createCookieAgent( BaseAgent: new (...rest: Params) => BaseAgent, ): new (...rest: ConstructorParams) => CookieAgent; -export const HttpCookieAgent: new (options: http.AgentOptions & CookieAgentOptions) => CookieAgent; -export const HttpsCookieAgent: new (options: https.AgentOptions & CookieAgentOptions) => CookieAgent; +export const HttpCookieAgent: new (options: HttpAgentOptions & CookieAgentOptions) => CookieAgent; +export const HttpsCookieAgent: new (options: HttpsAgentOptions & CookieAgentOptions) => CookieAgent; export const MixedCookieAgent: new ( - options: http.AgentOptions & https.AgentOptions & CookieAgentOptions, -) => CookieAgent; + options: HttpAgentOptions & HttpsAgentOptions & CookieAgentOptions, +) => CookieAgent; diff --git a/package.json b/package.json index 1091cdd1..96f5b9c7 100644 --- a/package.json +++ b/package.json @@ -52,6 +52,7 @@ "lint:eslint": "eslint --max-warnings 0 .", "lint:prettier": "prettier --check .", "lint:tsc": "tsc --noEmit", + "lint:tsc:types": "tsc --noEmit http/index.d.ts", "semantic-release": "semantic-release", "test": "NODE_OPTIONS=\"--experimental-vm-modules\" jest" }, diff --git a/src/http/create_cookie_agent.ts b/src/http/create_cookie_agent.ts index d658057f..f5b8b517 100644 --- a/src/http/create_cookie_agent.ts +++ b/src/http/create_cookie_agent.ts @@ -39,7 +39,7 @@ export function createCookieAgent = T extends http.AgentOptions ? T & CookieAgentOptions : T; type ConstructorParams = { [Index in keyof Params]: WithCookieAgentOptions; - } & { length: Params['length'] }; + }; // @ts-expect-error -- BaseAgentClass is type definition. class CookieAgent extends BaseAgentClass { From f8028202d472da35df9870b38492ddbd90af6788 Mon Sep 17 00:00:00 2001 From: 3846masa <3846masahiro+git@gmail.com> Date: Mon, 23 Sep 2024 20:14:58 +0900 Subject: [PATCH 2/3] fix: prefer to use wildcard import rather than alias named import --- http/index.d.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/http/index.d.ts b/http/index.d.ts index 1d61d418..1805c4b1 100644 --- a/http/index.d.ts +++ b/http/index.d.ts @@ -1,5 +1,5 @@ -import type { Agent as HttpAgent, AgentOptions as HttpAgentOptions } from 'node:http'; -import type { Agent as HttpsAgent, AgentOptions as HttpsAgentOptions } from 'node:https'; +import type * as http from 'node:http'; +import type * as https from 'node:https'; import type { CookieJar } from 'tough-cookie'; @@ -11,19 +11,19 @@ export type CookieAgentOptions = { cookies?: CookieOptions | undefined; }; -type CookieAgent = BaseAgent; +type CookieAgent = BaseAgent; -type WithCookieAgentOptions = T extends HttpAgentOptions ? T & CookieAgentOptions : T; +type WithCookieAgentOptions = T extends http.AgentOptions ? T & CookieAgentOptions : T; type ConstructorParams = { [Index in keyof Params]: WithCookieAgentOptions; }; -export function createCookieAgent( +export function createCookieAgent( BaseAgent: new (...rest: Params) => BaseAgent, ): new (...rest: ConstructorParams) => CookieAgent; -export const HttpCookieAgent: new (options: HttpAgentOptions & CookieAgentOptions) => CookieAgent; -export const HttpsCookieAgent: new (options: HttpsAgentOptions & CookieAgentOptions) => CookieAgent; +export const HttpCookieAgent: new (options: http.AgentOptions & CookieAgentOptions) => CookieAgent; +export const HttpsCookieAgent: new (options: https.AgentOptions & CookieAgentOptions) => CookieAgent; export const MixedCookieAgent: new ( - options: HttpAgentOptions & HttpsAgentOptions & CookieAgentOptions, -) => CookieAgent; + options: http.AgentOptions & https.AgentOptions & CookieAgentOptions, +) => CookieAgent; From 3d5ffd1c330805b1dac4413e6d2c7f0108dc0260 Mon Sep 17 00:00:00 2001 From: 3846masa <3846masahiro+git@gmail.com> Date: Mon, 23 Sep 2024 20:15:09 +0900 Subject: [PATCH 3/3] chore: fix npm scripts --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 96f5b9c7..f7b77191 100644 --- a/package.json +++ b/package.json @@ -49,10 +49,10 @@ "format:eslint": "eslint --fix .", "format:prettier": "prettier --write .", "lint": "pnpm run \"/^lint:.*/\"", + "lint:dts": "tsc --noEmit http/*.d.ts undici/*.d.ts", "lint:eslint": "eslint --max-warnings 0 .", "lint:prettier": "prettier --check .", "lint:tsc": "tsc --noEmit", - "lint:tsc:types": "tsc --noEmit http/index.d.ts", "semantic-release": "semantic-release", "test": "NODE_OPTIONS=\"--experimental-vm-modules\" jest" },