mirror of
https://github.com/webpack/tapable.git
synced 2026-02-01 16:07:39 +00:00
fix: support to pass return type for waterfall hooks (#191)
This commit is contained in:
parent
2da9b214b1
commit
25a2864796
@ -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", () => {
|
||||
|
||||
@ -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"]);
|
||||
|
||||
|
||||
6
tapable.d.ts
vendored
6
tapable.d.ts
vendored
@ -94,8 +94,9 @@ export class SyncLoopHook<
|
||||
> extends SyncHook<T, void, AdditionalOptions> {}
|
||||
export class SyncWaterfallHook<
|
||||
T,
|
||||
R = AsArray<T>[0],
|
||||
AdditionalOptions = UnsetAdditionalOptions
|
||||
> extends SyncHook<T, AsArray<T>[0] | void, AdditionalOptions> {}
|
||||
> extends SyncHook<T, R, AdditionalOptions> {}
|
||||
|
||||
declare class AsyncHook<
|
||||
T,
|
||||
@ -136,8 +137,9 @@ export class AsyncSeriesLoopHook<
|
||||
> extends AsyncHook<T, void, AdditionalOptions> {}
|
||||
export class AsyncSeriesWaterfallHook<
|
||||
T,
|
||||
R = AsArray<T>[0],
|
||||
AdditionalOptions = UnsetAdditionalOptions
|
||||
> extends AsyncHook<T, AsArray<T>[0] | void, AdditionalOptions> {}
|
||||
> extends AsyncHook<T, R, AdditionalOptions> {}
|
||||
|
||||
type HookFactory<H> = (key: any, hook?: H) => H;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user