diff --git a/lib/__tests__/AsyncSeriesHooks.js b/lib/__tests__/AsyncSeriesHooks.js index 4a3954f..80c1c63 100644 --- a/lib/__tests__/AsyncSeriesHooks.js +++ b/lib/__tests__/AsyncSeriesHooks.js @@ -100,6 +100,13 @@ describe("AsyncSeriesWaterfallHook", () => { hook.tap("undefined", () => null); return expect(hook.promise()).resolves.toBeNull(); }); + + it("should work with different types", async () => { + const hook = new AsyncSeriesWaterfallHook(["x"]); + hook.tap("number", () => 42); + hook.tap("string", () => "string"); + return expect(hook.promise()).resolves.toBe("string"); + }); }); describe("AsyncSeriesLoopHook", () => { diff --git a/lib/__tests__/SyncWaterfallHook.js b/lib/__tests__/SyncWaterfallHook.js index 15910d3..95d0019 100644 --- a/lib/__tests__/SyncWaterfallHook.js +++ b/lib/__tests__/SyncWaterfallHook.js @@ -59,6 +59,13 @@ describe("SyncWaterfallHook", () => { return expect(hook.call()).toBeNull(); }); + it("should work with different types", async () => { + const hook = new SyncWaterfallHook(["x"]); + hook.tap("number", () => 42); + hook.tap("string", () => "string"); + return expect(hook.call()).toBe("string"); + }); + it("should allow to create sync hooks", async () => { const hook = new SyncWaterfallHook(["arg1", "arg2"]); diff --git a/tapable.d.ts b/tapable.d.ts index 1ab087a..60dba25 100644 --- a/tapable.d.ts +++ b/tapable.d.ts @@ -94,8 +94,9 @@ export class SyncLoopHook< > extends SyncHook {} export class SyncWaterfallHook< T, + R = AsArray[0], AdditionalOptions = UnsetAdditionalOptions -> extends SyncHook[0] | void, AdditionalOptions> {} +> extends SyncHook {} declare class AsyncHook< T, @@ -136,8 +137,9 @@ export class AsyncSeriesLoopHook< > extends AsyncHook {} export class AsyncSeriesWaterfallHook< T, + R = AsArray[0], AdditionalOptions = UnsetAdditionalOptions -> extends AsyncHook[0] | void, AdditionalOptions> {} +> extends AsyncHook {} type HookFactory = (key: any, hook?: H) => H;