-
-
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
fix replaceReducer type #3507
fix replaceReducer type #3507
Conversation
Deploy preview for redux-docs ready! Built with commit 6b76c98 |
Deploy preview for redux-docs ready! Built with commit 500265f |
We should probably add some tests against those new types. |
|
@timdorr pushed a test, let me know if you think more is needed |
That's a good enough start for me. Thanks! |
Oh crap, I missed that this was supposed to be against master. Welp, we can wait until the full TS conversion is done. |
No worries, I only did it against master because that was one of 2 options, and this one is just fine too |
Currently, the
replaceReducer
function assumes that the reducer state stays in the same shape. This does not make sense, as the purpose ofreplaceReducer
is to change the store state.However, typescript types are static, and replaceReducer changes the type at run-time.
To solve this issue, we either need to cast the existing store to the new store type, or transform the store.
As it turns out, a simple solution is to modify the signature for
replaceReducer
to return the existing store, and this gives us the ability to typecast to the new reducer type in a graceful way.With this change, the
combineReducers
test passes when converted to typescript with minimal changes.This may also fix #3482