Skip to content

Commit 47ee22b

Browse files
authored
Revert "Infer action types from combineReducers" (reduxjs#3467)
This reverts commit 2954f00.
1 parent 99b6b5e commit 47ee22b

File tree

2 files changed

+16
-18
lines changed

2 files changed

+16
-18
lines changed

index.d.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,12 @@ export type ReducersMapObject<S = any, A extends Action = Action> = {
9090
* @returns A reducer function that invokes every reducer inside the passed
9191
* object, and builds a state object with the same shape.
9292
*/
93-
export function combineReducers<T extends ReducersMapObject<any, any>>(
94-
reducers: T
95-
): Reducer<InferStateType<T>, InferActionTypes<InferReducerTypes<T>>>
96-
97-
type InferActionTypes<R> = R extends Reducer<any, infer A> ? A : AnyAction
98-
type InferReducerTypes<T> = T extends Record<any, infer R> ? R : Reducer
99-
type InferStateType<T> = T extends ReducersMapObject<infer S, any> ? S : never
93+
export function combineReducers<S>(
94+
reducers: ReducersMapObject<S, any>
95+
): Reducer<S>
96+
export function combineReducers<S, A extends Action = AnyAction>(
97+
reducers: ReducersMapObject<S, A>
98+
): Reducer<S, A>
10099

101100
/* store */
102101

test/typescript/reducers.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ function simple() {
4242
// Combined reducer also accepts any action.
4343
const combined = combineReducers({ sub: reducer })
4444

45-
let cs = combined(undefined, { type: 'init' })
45+
let cs: { sub: State } = combined(undefined, { type: 'init' })
4646
cs = combined(cs, { type: 'INCREMENT', count: 10 })
4747

4848
// Combined reducer's state is strictly checked.
@@ -110,18 +110,17 @@ function discriminated() {
110110
// typings:expect-error
111111
s = reducer(s, { type: 'SOME_OTHER_TYPE', someField: 'value' })
112112

113-
// Combined reducer accepts a union actions types accepted each reducer,
114-
// which can be very permissive for unknown third-party reducers.
115-
const combined = combineReducers({
116-
sub: reducer,
117-
unknown: (state => state) as Reducer
118-
})
113+
// Combined reducer accepts any action by default which allows to include
114+
// third-party reducers without the need to add their actions to the union.
115+
const combined = combineReducers({ sub: reducer })
119116

120-
let cs = combined(undefined, { type: 'init' })
121-
cs = combined(cs, { type: 'SOME_OTHER_TYPE', someField: 'value' })
117+
let cs: { sub: State } = combined(undefined, { type: 'init' })
118+
cs = combined(cs, { type: 'SOME_OTHER_TYPE' })
122119

123120
// Combined reducer can be made to only accept known actions.
124-
const strictCombined = combineReducers({ sub: reducer })
121+
const strictCombined = combineReducers<{ sub: State }, MyAction>({
122+
sub: reducer
123+
})
125124

126125
strictCombined(cs, { type: 'INCREMENT' })
127126
// typings:expect-error
@@ -180,7 +179,7 @@ function typeGuards() {
180179

181180
const combined = combineReducers({ sub: reducer })
182181

183-
let cs = combined(undefined, { type: 'init' })
182+
let cs: { sub: State } = combined(undefined, { type: 'init' })
184183
cs = combined(cs, { type: 'INCREMENT', count: 10 })
185184
}
186185

0 commit comments

Comments
 (0)