-
-
Notifications
You must be signed in to change notification settings - Fork 15.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
typings for combineReducers infers overly action type from reducer map #2979
Comments
We're using Typescript 2.8. Feel free to submit a PR. |
It would prevent anyone using earlier releases of TypeScript from using the official redux typings. It would also break for those explicitly specifying the state/action type parameters. You could argue that with this level of inference there's no longer a need to use those parameters, but some might be using them to explicitly verify their reducer map functions. I like it this way at least ;) |
@ohjames thank you! Your solution was very helpful. I slightly modified it: type ReducersMapObject = { [index: string]: Reducer<any, any> };
type CombinedState<T extends ReducersMapObject> = { [K in keyof T]: ReturnType<T[K]> };
type ObjectValues<T> = T[keyof T];
type CombinedActions<T extends ReducersMapObject> = ObjectValues<
{ [K in keyof T]: Parameters<T[K]>[1] /* <- type of action parameter */ }
>;
type CombinedReducer<T extends ReducersMapObject> = Reducer<
CombinedState<T>,
CombinedActions<T>
>;
|
I’ve opened a pull request for this issue, #3484. |
* Add type overload for combineReducers which strictly infers state shape and actions from the reducers object map. * Fixed some typos. * Please don't change version numbers in a PR * Typescript 2.8 default type fixes.
Do you want to request a feature or report a bug?
Bug
What is the current behavior?
The following minimal reproduction shows the reducer is incorrectly typed to accept
AnyAction
What is the expected behavior?
The action types should be inferred from the action. If the typings are changed to this it works:
But this relies on conditional types which were added in typescript
2.8
.Which versions of Redux, and which browser and OS are affected by this issue? Did this work in previous versions of Redux?
Redux 4.0.0
The text was updated successfully, but these errors were encountered: