Skip to content
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

Infer action types from combineReducers #3411

Merged
merged 2 commits into from
Apr 23, 2019
Merged

Conversation

appden
Copy link
Contributor

@appden appden commented Apr 23, 2019

This change allows for combineReducers to completely infer both the state and action types for its returned reducer.

From experience with large TypeScript projects, it's common to see that the action type is not explicitly specified, which results in AnyAction in the resulting reducer type. Unfortunately, this will propagate through the type inference for createStore resulting in dispatch being very weakly typed. This change alone causes a chain reaction of a more correctly (and strongly) typed project with regards to Redux.

This change allows for `combineReducers` to completely infer both the state and action types for its returned reducer.

From experience with large TypeScript projects, it's common to see that the action type is not explicitly specified, which results in `AnyAction` in the resulting reducer type. Unfortunately, this will propagate through the type inference for `createStore` resulting in `dispatch` being very weakly typed. This change alone causes a chain reaction of a more correctly (and strongly) typed project with regards to Redux.
@netlify
Copy link

netlify bot commented Apr 23, 2019

Deploy preview for redux-docs ready!

Built with commit 6fe5614

https://deploy-preview-3411--redux-docs.netlify.com

@timdorr
Copy link
Member

timdorr commented Apr 23, 2019

Ah, good use of the infer keyword. When these were last touched, it was prior to TS 2.8, so that kind of thing wasn't even possible.

Looks like some other formatting things came up unrelated to this PR. I'll see about fixing that up for you.

@timdorr timdorr merged commit c676a25 into reduxjs:master Apr 23, 2019
timdorr added a commit that referenced this pull request Jul 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants