Skip to content

Commit fe1e9ba

Browse files
deniswmarkerikson
authored andcommitted
Return Reducer<S, AnyAction> from createReducer (#104)
This is more correct as the generated reducer does, in fact, support passing actions other than the ones explicitly handled. Also, this fixes an incompatibility with `configureStore` (#102).
1 parent 0118f1f commit fe1e9ba

File tree

2 files changed

+4
-7
lines changed

2 files changed

+4
-7
lines changed

src/createReducer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,14 @@ export interface CaseReducersMapObject<S = any, A extends Action = AnyAction> {
4646
export function createReducer<S = any, A extends Action = AnyAction>(
4747
initialState: S,
4848
actionsMap: CaseReducersMapObject<S, A>
49-
): Reducer<S, A> {
49+
): Reducer<S> {
5050
return function(state = initialState, action): S {
5151
// @ts-ignore createNextState() produces an Immutable<Draft<S>> rather
5252
// than an Immutable<S>, and TypeScript cannot find out how to reconcile
5353
// these two types.
5454
return createNextState(state, (draft: Draft<S>) => {
5555
const caseReducer = actionsMap[action.type]
56-
return caseReducer ? caseReducer(draft, action) : undefined
56+
return caseReducer ? caseReducer(draft, action as A) : undefined
5757
})
5858
}
5959
}

type-tests/files/createReducer.typetest.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,10 @@ import { AnyAction, createReducer, Reducer } from 'redux-starter-kit'
1616
decrement: decrementHandler
1717
})
1818

19-
const numberReducer: Reducer<number, CounterAction> = reducer
19+
const numberReducer: Reducer<number> = reducer
2020

2121
// typings:expect-error
22-
const stringReducer: Reducer<string, CounterAction> = reducer
23-
24-
// typings:expect-error
25-
const anyActionReducer: Reducer<number, AnyAction> = reducer
22+
const stringReducer: Reducer<string> = reducer
2623
}
2724

2825
/**

0 commit comments

Comments
 (0)