From aee99a37affd8d32860116004d9f87a7237a7811 Mon Sep 17 00:00:00 2001 From: Ha-limLee Date: Sun, 5 Nov 2023 00:41:27 +0900 Subject: [PATCH 1/2] Type take for patterns --- types/index.d.ts | 5 +++++ 1 file changed, 5 insertions(+) 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, From 74509958547fe7117f6190a6991552736cf21cee Mon Sep 17 00:00:00 2001 From: Ha-limLee Date: Sun, 5 Nov 2023 01:00:59 +0900 Subject: [PATCH 2/2] Add take patterns type test --- types/index.test.ts | 4 ++++ 1 file changed, 4 insertions(+) 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