fix(store): fix typing of on fn#3577
Conversation
✅ Deploy Preview for ngrx-io canceled.
|
| ...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.
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.
Specifically, this allowed for generic reducers: https://github.com/ngrx/platform/pull/2996/files#diff-b5b61b5c88ce4368769a58df0918602484c6c507e6a6dfad51e4746e470caf26R45
There was a problem hiding this comment.
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.
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.
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.
Cool! TS is a blast 😄
43d1d9d to
71094ef
Compare
timdeschryver
left a comment
There was a problem hiding this comment.
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?
onfunction when created outside ofcreateReducerfactory function #3576What is the current behavior?
Closes #3576
What is the new behavior?
Does this PR introduce a breaking change?
Other information