From a7441d8aaa44f9eec111a23a5df238d77b150c3a Mon Sep 17 00:00:00 2001 From: Aras Abbasi Date: Tue, 18 Jun 2024 09:12:21 +0200 Subject: [PATCH] fix: interceptors.d.ts has no default export (#3332) * fix: types interceptors default export * test for bugs in typescript --- package.json | 2 +- types/formdata.d.ts | 2 +- types/index.d.ts | 8 ++------ types/interceptors.d.ts | 18 +++++++++++------- types/retry-agent.d.ts | 3 --- types/webidl.d.ts | 4 +--- 6 files changed, 16 insertions(+), 21 deletions(-) diff --git a/package.json b/package.json index 254e0d9f2a6..05e1172086b 100644 --- a/package.json +++ b/package.json @@ -85,7 +85,7 @@ "test:node-test": "borp -p \"test/node-test/**/*.js\"", "test:tdd": "borp --expose-gc -p \"test/*.js\"", "test:tdd:node-test": "borp -p \"test/node-test/**/*.js\" -w", - "test:typescript": "tsd && tsc --skipLibCheck test/imports/undici-import.ts", + "test:typescript": "tsd && tsc test/imports/undici-import.ts --typeRoots ./types && tsc ./types/*.d.ts --noEmit --typeRoots ./types", "test:webidl": "borp -p \"test/webidl/*.js\"", "test:websocket": "borp -p \"test/websocket/*.js\"", "test:websocket:autobahn": "node test/autobahn/client.js", diff --git a/types/formdata.d.ts b/types/formdata.d.ts index df29a572d6b..e676b11ec34 100644 --- a/types/formdata.d.ts +++ b/types/formdata.d.ts @@ -2,7 +2,7 @@ /// import { File } from './file' -import { SpecIterator, SpecIterableIterator } from './fetch' +import { SpecIterableIterator } from './fetch' /** * A `string` or `File` that represents a single value from a set of `FormData` key-value pairs. diff --git a/types/index.d.ts b/types/index.d.ts index 18657b6aeb7..f6be35cd9bf 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -42,7 +42,7 @@ declare namespace Undici { var RedirectHandler: typeof import ('./handlers').RedirectHandler var DecoratorHandler: typeof import ('./handlers').DecoratorHandler var RetryHandler: typeof import ('./retry-handler').default - var createRedirectInterceptor: typeof import ('./interceptors').createRedirectInterceptor + var createRedirectInterceptor: typeof import ('./interceptors').default.createRedirectInterceptor var BalancedPool: typeof import('./balanced-pool').default; var Client: typeof import('./client').default; var buildConnector: typeof import('./connector').default; @@ -67,9 +67,5 @@ declare namespace Undici { var File: typeof import('./file').File; var FileReader: typeof import('./filereader').FileReader; var caches: typeof import('./cache').caches; - var interceptors: { - dump: typeof import('./interceptors').dump; - retry: typeof import('./interceptors').retry; - redirect: typeof import('./interceptors').redirect; - } + var interceptors: typeof import('./interceptors').default; } diff --git a/types/interceptors.d.ts b/types/interceptors.d.ts index d546ac344e3..fab6da08c0d 100644 --- a/types/interceptors.d.ts +++ b/types/interceptors.d.ts @@ -1,11 +1,15 @@ import Dispatcher from "./dispatcher"; import RetryHandler from "./retry-handler"; -export type DumpInterceptorOpts = { maxSize?: number } -export type RetryInterceptorOpts = RetryHandler.RetryOptions -export type RedirectInterceptorOpts = { maxRedirections?: number } +export default Interceptors; -export declare function createRedirectInterceptor (opts: RedirectInterceptorOpts): Dispatcher.DispatcherComposeInterceptor -export declare function dump(opts?: DumpInterceptorOpts): Dispatcher.DispatcherComposeInterceptor -export declare function retry(opts?: RetryInterceptorOpts): Dispatcher.DispatcherComposeInterceptor -export declare function redirect(opts?: RedirectInterceptorOpts): Dispatcher.DispatcherComposeInterceptor +declare namespace Interceptors { + export type DumpInterceptorOpts = { maxSize?: number } + export type RetryInterceptorOpts = RetryHandler.RetryOptions + export type RedirectInterceptorOpts = { maxRedirections?: number } + + export function createRedirectInterceptor(opts: RedirectInterceptorOpts): Dispatcher.DispatcherComposeInterceptor + export function dump(opts?: DumpInterceptorOpts): Dispatcher.DispatcherComposeInterceptor + export function retry(opts?: RetryInterceptorOpts): Dispatcher.DispatcherComposeInterceptor + export function redirect(opts?: RedirectInterceptorOpts): Dispatcher.DispatcherComposeInterceptor +} diff --git a/types/retry-agent.d.ts b/types/retry-agent.d.ts index cf559d956e5..963cea99e42 100644 --- a/types/retry-agent.d.ts +++ b/types/retry-agent.d.ts @@ -1,7 +1,4 @@ -import Agent from './agent' -import buildConnector from './connector'; import Dispatcher from './dispatcher' -import { IncomingHttpHeaders } from './header' import RetryHandler from './retry-handler' export default RetryAgent diff --git a/types/webidl.d.ts b/types/webidl.d.ts index fe802a20124..8a23a85bf01 100644 --- a/types/webidl.d.ts +++ b/types/webidl.d.ts @@ -55,9 +55,7 @@ interface WebidlUtil { V: unknown, bitLength: number, signedness: 'signed' | 'unsigned', - opts?: ConvertToIntOpts, - prefix: string, - argument: string + opts?: ConvertToIntOpts ): number /**