diff --git a/types/index.d.ts b/types/index.d.ts index 5b079cf..d5cc428 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -50,6 +50,8 @@ export type SagaGenerator> = Generator< RT >; +type ExtractAction = T extends ActionPattern ? A : never; + export function take( pattern?: ActionPattern, ): SagaGenerator; @@ -58,6 +60,9 @@ export function take( multicastPattern?: Pattern, ): SagaGenerator>; export function take(pattern?: ActionPattern): SagaGenerator; +export function take( + patterns: T, +): SagaGenerator, TakeEffect>; export function takeMaybe( pattern?: ActionPattern, diff --git a/types/index.test.ts b/types/index.test.ts index 5745d5e..77b6d5d 100644 --- a/types/index.test.ts +++ b/types/index.test.ts @@ -13,6 +13,10 @@ function* mySaga(): Effects.SagaGenerator { yield* Effects.take("FOO"); // $ExpectType Action type FooAction = { readonly type: "FOO" }; yield* Effects.take("FOO"); // $ExpectType FooAction + const fooActionCreator = (payload: number) => ({ type: 'foo' as const, payload }); + const barActionCreator = (payload: string[]) => ({ type: 'bar' as const, payload }); + // $ExpectType { type: "foo"; payload: number; } | { type: "bar"; payload: string[]; } + yield* Effects.take([fooActionCreator, barActionCreator]); yield* Effects.takeMaybe("FOO"); // $ExpectType Action yield* Effects.takeMaybe("FOO"); // $ExpectType FooAction