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

bug(store) add explicit overloads for createSelector #3354

Merged

Conversation

david-shortman
Copy link
Contributor

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 #3268

What is the new behavior?

Does this PR introduce a breaking change?

[ ] Yes
[x] No

Other information

I only added explicit overloads for createSelector with variadic "slice" arguments, because only that signature failed due to the problems identified in #3268. The signature that uses an array for the "slices" does not fail.

@netlify
Copy link

netlify bot commented Mar 25, 2022

Deploy Preview for ngrx-io canceled.

Built without sensitive environment variables

Name Link
🔨 Latest commit a9ffd41
🔍 Latest deploy log https://app.netlify.com/sites/ngrx-io/deploys/623d12b0876ca400095b29f6

Comment on lines +196 to +199
...args: [...slices: Selector<State, unknown>[], projector: unknown] &
[
...{ [i in keyof Slices]: Selector<State, Slices[i]> },
(...s: Slices) => Result
...slices: { [i in keyof Slices]: Selector<State, Slices[i]> },
projector: (...s: Slices) => Result
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added names to clarify what these tuples represented.

Copy link
Member

Choose a reason for hiding this comment

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

Nice, I didn't know we could do that! 🤩

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's quite handy bc variadic tuple types become quite cumbersome looking quickly 😅

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.

It seems like the case of the issue isn't resolved with this fix, but I can't figure out how to do it otherwise... This should cover most of the cases imo, which is better than nothing.

const state: {first : string} = { first: 'state' };

const getData = <T>(d: T): T => d;
const returnState = () => state;

const selector = createSelector(returnState, getData);
expect(selector(state).first).toEqual('state');

Also, would it be possible to move the tuple version to the top and add a @deprecated annotation to the re-added selectors?
This seems fine for the selectors in the example app but since I don't have a reproduction of the issue, I can't confirm that this works correctly for the deprecated cases.

@mattlewis92 would it be possible if you confirm this fix in your repo?

@david-shortman
Copy link
Contributor Author

It seems like the case of the issue isn't resolved with this fix, but I can't figure out how to do it otherwise... This should cover most of the cases imo, which is better than nothing.

This appears to verify that the case presented in the issue works: playground.

@david-shortman
Copy link
Contributor Author

Also, would it be possible to move the tuple version to the top and add a @deprecated annotation to the re-added selectors? This seems fine for the selectors in the example app but since I don't have a reproduction of the issue, I can't confirm that this works correctly for the deprecated cases.

The order cannot be changed, as then the variadic signature will always match. This error is demonstrated in this playground.

@mattlewis92
Copy link

@mattlewis92 would it be possible if you confirm this fix in your repo?

Sure thing, I just checked it in our repo with this change and it now all builds correctly! 🙌

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 @david-shortman , and also thanks @mattlewis92 for the verification.

@brandonroberts brandonroberts merged commit 2f82101 into ngrx:master Mar 26, 2022
@david-shortman david-shortman deleted the explicit-selector-overloads branch March 27, 2022 14:23
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.

Type inference for createSelector is broken since changing to variadic tuple types
4 participants