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

fix(store): fix typing of on fn #3577

Merged
merged 3 commits into from
Sep 19, 2022

Conversation

alex-okrushko
Copy link
Member

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

[x] Bugfix
[ ] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Build related changes
[ ] CI related changes
[ ] Documentation content changes
[ ] Other... Please describe:

What is the current behavior?

Closes #3576

What is the new behavior?

Does this PR introduce a breaking change?

[ ] Yes
[x] No

Other information

@netlify
Copy link

netlify bot commented Sep 16, 2022

Deploy Preview for ngrx-io canceled.

Name Link
🔨 Latest commit 57b2387
🔍 Latest deploy log https://app.netlify.com/sites/ngrx-io/deploys/6328a9fdc5901e0009e7a46c

...creators: Creators,
reducer: OnReducer<State extends infer S ? S : never, Creators>
]
...args: [...creators: Creators, reducer: OnReducer<State, Creators>]
Copy link
Contributor

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

@david-shortman david-shortman Sep 16, 2022

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.

Copy link
Contributor

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.

Copy link
Contributor

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.

Here's the playground link

Copy link
Contributor

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 😄

modules/store/src/reducer_creator.ts Outdated Show resolved Hide resolved
Copy link
Member

@timdeschryver timdeschryver left a 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>
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.

Broken type of on function when created outside of createReducer factory function
5 participants