Skip to content

Commit

Permalink
Fix type definition for Client Interceptors (#2269)
Browse files Browse the repository at this point in the history
Updating the client constructor to accept an array of interceptor
functions to match the documentation.
  • Loading branch information
ComradeCow authored Sep 19, 2023
1 parent 8c5577b commit 4d7c319
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
12 changes: 12 additions & 0 deletions test/types/client.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,18 @@ expectAssignable<Client>(new Client(new URL('http://localhost'), {}))
expectAssignable<Client>(new Client('', {
autoSelectFamilyAttemptTimeout: 300e3
}))
expectAssignable<Client>(new Client('', {
interceptors: {
Client: [(dispatcher) => {
expectAssignable<Dispatcher['dispatch']>(dispatcher);
return (opts, handlers) => {
expectAssignable<Dispatcher.DispatchOptions>(opts);
expectAssignable<Dispatcher.DispatchHandlers>(handlers);
return dispatcher(opts, handlers)
}
}]
}
}))
}

{
Expand Down
3 changes: 1 addition & 2 deletions types/client.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { URL } from 'url'
import { TlsOptions } from 'tls'
import Dispatcher from './dispatcher'
import DispatchInterceptor from './dispatcher'
import buildConnector from "./connector";

/**
Expand All @@ -19,7 +18,7 @@ export class Client extends Dispatcher {

export declare namespace Client {
export interface OptionsInterceptors {
Client: readonly DispatchInterceptor[];
Client: readonly Dispatcher.DispatchInterceptor[];
}
export interface Options {
/** TODO */
Expand Down

0 comments on commit 4d7c319

Please sign in to comment.