Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix #2982] use DispatcherInterceptor type for Dispatcher#Compose #2983

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading