-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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(store): fix typing of on fn #3577
Conversation
✅ Deploy Preview for ngrx-io canceled.
|
modules/store/src/reducer_creator.ts
Outdated
...creators: Creators, | ||
reducer: OnReducer<State extends infer S ? S : never, Creators> | ||
] | ||
...args: [...creators: Creators, reducer: OnReducer<State, Creators>] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While this fixes the issue of inferring State
when on
is used outside createReducer
, I would expect that it breaks the deferred contextual inference which was intended by using the conditional type. Do the current tests ensure that State
is inferred contextually from on
's usage in the parameters of a function like createReducer
? Otherwise, I'd expect this could break some intended functionality.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Specifically, this allowed for generic reducers: https://github.com/ngrx/platform/pull/2996/files#diff-b5b61b5c88ce4368769a58df0918602484c6c507e6a6dfad51e4746e470caf26R45
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In that last PR, it seems the effect of using the conditional type was not understood. Here's why it worked- https://stackoverflow.com/a/70129630/11087018.
I'm not immediately sure what the correct thing to do would be to support both use cases. Probably a good question for jcalz, StackOverflow's Typescript wizard.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @david-shortman
Yes, we have a test covering a generic reducer as well.
There are number of test still broken, so this is not the final fix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, this was fun :)
@david-shortman this should be now fixed with preserving generic reducers and all the other interesting cases that we were running into.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool! TS is a blast 😄
43d1d9d
to
71094ef
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the added comments 👍
Co-authored-by: Brandon <robertsbt@gmail.com>
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
on
function when created outside ofcreateReducer
factory function #3576What is the current behavior?
Closes #3576
What is the new behavior?
Does this PR introduce a breaking change?
Other information