I am using combineReducers
in my React TypeScript app:
// combinedReducer.ts
import { combineReducers } from \'redux\'
import reducer1 from \'./r
Ensure that Redux is at version 4.0.0 or higher. The type mappings for combineReducers was released with version 4.0.0, here's the related PR on the redux github.
You can update your package.json file:
...
"dependencies": {
"redux": "^4.0.3"
}
...
Then run npm install to update to the latest version.
Once you've made this change, make sure you restart your IDE to reload the type mappings.
Same problem for me using redux 4.0.5 and typescript 4.0.1. Had to write a inferrer myself:
type BaseReducerMap<S> = {
[K in keyof S]: (state: S[K], action: any) => S
}
export type InferRootState<ReducerMap extends BaseReducerMap<S>, S = any> = {
[K in keyof ReducerMap]: ReturnType<ReducerMap[K]>
}
Then for your set of reducers (before you combine them)
const reducers = {
login: loginReducer,
chatUsers: chatUsersReducer,
};
const combinedReducer = combineReducers(reducers);
export type State = InferRootState<typeof reducers>;
Then typescript can successfully infer the type of my State
.
I don't know why it fails in this version.