Skip to content

Commit

Permalink
[fix nodejs#2982] use DispatcherInterceptor type for Dispatcher#Compo…
Browse files Browse the repository at this point in the history
…se (nodejs#2983)
  • Loading branch information
clovis-guillemot authored Mar 22, 2024
1 parent fcbf6de commit 8fce214
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
30 changes: 28 additions & 2 deletions test/types/dispatcher.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,34 @@ declare const { body }: Dispatcher.ResponseData;

// compose
{
expectAssignable<Dispatcher.ComposedDispatcher>(new Dispatcher().compose(new Dispatcher().dispatch, new Dispatcher().dispatch))
expectAssignable<Dispatcher.ComposedDispatcher>(new Dispatcher().compose([new Dispatcher().dispatch, new Dispatcher().dispatch]))
expectAssignable<Dispatcher.ComposedDispatcher>(new Dispatcher().compose(
(dispatcher) => {
expectAssignable<Dispatcher['dispatch']>(dispatcher);
return (opts, handlers) => {
expectAssignable<Dispatcher.DispatchOptions>(opts);
expectAssignable<Dispatcher.DispatchHandlers>(handlers);
return dispatcher(opts, handlers)
}
}
))
expectAssignable<Dispatcher.ComposedDispatcher>(new Dispatcher().compose([
(dispatcher) => {
expectAssignable<Dispatcher['dispatch']>(dispatcher);
return (opts, handlers) => {
expectAssignable<Dispatcher.DispatchOptions>(opts);
expectAssignable<Dispatcher.DispatchHandlers>(handlers);
return dispatcher(opts, handlers)
}
},
(dispatcher) => {
expectAssignable<Dispatcher['dispatch']>(dispatcher);
return (opts, handlers) => {
expectAssignable<Dispatcher.DispatchOptions>(opts);
expectAssignable<Dispatcher.DispatchHandlers>(handlers);
return dispatcher(opts, handlers)
}
}
]))
}

{
Expand Down
4 changes: 2 additions & 2 deletions types/dispatcher.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ declare class Dispatcher extends EventEmitter {
connect(options: Dispatcher.ConnectOptions): Promise<Dispatcher.ConnectData>;
connect(options: Dispatcher.ConnectOptions, callback: (err: Error | null, data: Dispatcher.ConnectData) => void): void;
/** Compose a chain of dispatchers */
compose(dispatchers: Dispatcher['dispatch'][]): Dispatcher.ComposedDispatcher;
compose(...dispatchers: Dispatcher['dispatch'][]): Dispatcher.ComposedDispatcher;
compose(dispatchers: Dispatcher.DispatcherInterceptor[]): Dispatcher.ComposedDispatcher;
compose(...dispatchers: Dispatcher.DispatcherInterceptor[]): Dispatcher.ComposedDispatcher;
/** Performs an HTTP request. */
request(options: Dispatcher.RequestOptions): Promise<Dispatcher.ResponseData>;
request(options: Dispatcher.RequestOptions, callback: (err: Error | null, data: Dispatcher.ResponseData) => void): void;
Expand Down

0 comments on commit 8fce214

Please sign in to comment.