diff --git a/test/types/dispatcher.test-d.ts b/test/types/dispatcher.test-d.ts index 275d88c4af9..245ee218d59 100644 --- a/test/types/dispatcher.test-d.ts +++ b/test/types/dispatcher.test-d.ts @@ -127,6 +127,12 @@ expectAssignable(new Dispatcher()) declare const { body }: Dispatcher.ResponseData; +// compose +{ + expectAssignable(new Dispatcher().compose(new Dispatcher().dispatch, new Dispatcher().dispatch)) + expectAssignable(new Dispatcher().compose([new Dispatcher().dispatch, new Dispatcher().dispatch])) +} + { // body mixin tests expectType(body.body) diff --git a/types/dispatcher.d.ts b/types/dispatcher.d.ts index 08c59ca0718..e632e0e921a 100644 --- a/types/dispatcher.d.ts +++ b/types/dispatcher.d.ts @@ -18,6 +18,9 @@ declare class Dispatcher extends EventEmitter { /** Starts two-way communications with the requested resource. */ connect(options: Dispatcher.ConnectOptions): Promise; 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; /** Performs an HTTP request. */ request(options: Dispatcher.RequestOptions): Promise; request(options: Dispatcher.RequestOptions, callback: (err: Error | null, data: Dispatcher.ResponseData) => void): void; @@ -93,6 +96,8 @@ declare class Dispatcher extends EventEmitter { } declare namespace Dispatcher { + export interface ComposedDispatcher extends Dispatcher {} + export type DispatcherInterceptor = (dispatch: Dispatcher['dispatch']) => Dispatcher['dispatch']; export interface DispatchOptions { origin?: string | URL; path: string;