You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The type definition for defining Client interceptors doesn't match the documentation. The Client constructor is expecting an array of Dispatchers, not the interceptor functions.
src/lib/quote/try.ts:13:28 - error TS2322: Type '(dispatch: (options: DispatchOptions, handler: DispatchHandlers) => boolean) => (opts: DispatchOptions, handler: DispatchHandlers) => boolean' is not assignable to type 'Dispatcher'.
13 interceptors: { Client: [insertHeaderInterceptor] },
~~~~~~~~~~~~~~~~~~~~~~~
I also tried:
import{Client,Dispatcher}from"undici";// the change from above is explicitly defining the type for the interceptor to match// the intentconstinsertHeaderInterceptor: Dispatcher.DispatchInterceptor=(dispatch: Dispatcher["dispatch"])=>{returnfunctionInterceptedDispatch(opts: Dispatcher.DispatchOptions,handler: Dispatcher.DispatchHandlers){returndispatch(opts,handler);};};constclient=newClient("https://localhost:3000",{interceptors: {Client: [insertHeaderInterceptor]},});
But the error is the same:
src/lib/quote/try.ts:15:28 - error TS2322: Type 'DispatchInterceptor' is not assignable to type 'Dispatcher'.
15 interceptors: { Client: [insertHeaderInterceptor] },
~~~~~~~~~~~~~~~~~~~~~~~
It looks like this bug comes from using the default import multiple times in types/client.d.ts - that imports the Dispatcher class twice, not the DispatchInterceptor interface.
The text was updated successfully, but these errors were encountered:
Bug Description
The type definition for defining Client interceptors doesn't match the documentation. The Client constructor is expecting an array of Dispatchers, not the interceptor functions.
Reproducible By
Install TypeScript 5.2.2, undici 5.24.0.
The error returned by TypeScript:
I also tried:
But the error is the same:
Expected Behavior
The code sample should successfully type check.
Environment
Windows 11 / WSL - Ubuntu 20.04 / Node v20.6.1 / TypeScript 5.2.2
Additional context
It looks like this bug comes from using the default import multiple times in
types/client.d.ts
- that imports the Dispatcher class twice, not theDispatchInterceptor
interface.The text was updated successfully, but these errors were encountered: