From 024893d06dc605f691e2e03d77d9b79c10767c91 Mon Sep 17 00:00:00 2001 From: David Philipson Date: Fri, 10 Jul 2020 10:40:34 -0700 Subject: [PATCH] Avoid AnyAction in return type, clarify docs --- README.md | 5 +++-- src/index.ts | 9 +++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 3111319..14a3cf3 100644 --- a/README.md +++ b/README.md @@ -206,7 +206,7 @@ composing reducers for which initial state is unnecessary. Note that since the type of the state cannot be inferred from the initial state, it must be provided as a type parameter: -```javascript +```ts const reducer = reducerWithoutInitialState() .case(setName, setNameHandler) .case(addBalance, addBalanceHandler) @@ -394,7 +394,8 @@ There are two reasons you may want to do this: separate NPM packages, you may run into type errors since the exported reducer has type `ReducerBuilder`, which the consuming package does not recognize unless it also depends on `typescript-fsa-reducers`. This is - avoided by returning a plain function instead. + avoided by calling `.build()`, whose return type is a plain function + instead. Example usage: diff --git a/src/index.ts b/src/index.ts index 5a08ecc..5a4f1e2 100644 --- a/src/index.ts +++ b/src/index.ts @@ -70,12 +70,13 @@ export interface ReducerBuilder { ) => ReducerBuilder, ): ReducerBuilder; - // Intentionally avoid AnyAction in return type so packages can export reducers - // created using .default() or .build() without requiring a dependency on typescript-fsa. + // Intentionally avoid AnyAction in return type so packages can export + // reducers created using .default() or .build() without consumers requiring + // a dependency on typescript-fsa. default( defaultHandler: Handler, - ): (state: PassedS, action: AnyAction) => OutS; - build(): (state: PassedS, action: AnyAction) => OutS; + ): (state: PassedS, action: { type: any }) => OutS; + build(): (state: PassedS, action: { type: any }) => OutS; (state: PassedS, action: AnyAction): OutS; }