Skip to content

Commit

Permalink
Avoid AnyAction in return type, clarify docs
Browse files Browse the repository at this point in the history
  • Loading branch information
dphilipson committed Jul 10, 2020
1 parent c9cb68d commit 024893d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<State>()
.case(setName, setNameHandler)
.case(addBalance, addBalanceHandler)
Expand Down Expand Up @@ -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:

Expand Down
9 changes: 5 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,13 @@ export interface ReducerBuilder<InS, OutS = InS, PassedS = InS | undefined> {
) => ReducerBuilder<InS, OutS, PassedS>,
): ReducerBuilder<InS, OutS, PassedS>;

// 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<InS, OutS, AnyAction>,
): (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;
}

Expand Down

0 comments on commit 024893d

Please sign in to comment.