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

Infer correct state when input selectors are a mix of explicit and rest syntax in createSelector #602

Merged
merged 3 commits into from
Apr 16, 2023

Conversation

PeterBul
Copy link

@PeterBul PeterBul commented Mar 15, 2023

The state parameter of the result of createSelector was of type never if input selectors were a mix of explicit and spread selectors. Additionally, the type of extra parameters are lost if the input has this format.

This PR aims to allow the combining of explicitly defined input selectors and using rest syntax in the end. It does so by making sure that the type of the array that is part of the rest syntax is transformed into a normal type before merging the parameter tuples. This is valid since we really don't care whether we have 1 or 10 selectors in the array that is spread as long as the types are the same.

This is related to issue 601 where some more details can be found in the conversation.

PeterBul and others added 3 commits March 15, 2023 10:16
The state parameter of the result of createSelector was of type never if input selectors were a mix of explicit and spread selectors
Previous test implies that different input state types are not supported in inference, only the state of the first selector is picked. Advanced tests for different input states in selectors therefore have to be removed since typescript v4.6 and before does not support it. Additionally, parameter is added to test, to test that the parameter is included in the output selector paraemeters.
…d rest syntax

This makes sure that extra parameters from input selectors are not lost when using a combination of explicit parameters and rest syntax.
type UnknownFunction = (...args: any[]) => any

type LongestTuple<T extends readonly unknown[][]> = T extends [
Copy link
Author

Choose a reason for hiding this comment

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

The readonly unknown[][] requirement has to be removed from several places since ReverseHead and ReverseTail use recursive types to find the first an last tuple element. Typescript complains when a condition (like readonly unknown[][]) has to to be compared with a type that is recursive, since it can't check the result of that type.

The checks of whether a type is readonly unknown[][] are moved to conditintional types instead where it is needed.

These are internal types specifically used for this use case, so removing the requirement should not be an issue.

@PeterBul PeterBul changed the title Infer correct state when input selectors are mix of explicit and spread in creatSelector Infer correct state when input selectors are a mix of explicit and rest syntax in createSelector Mar 16, 2023
@markerikson markerikson changed the base branch from master to 4.x April 16, 2023 20:16
@markerikson markerikson merged commit 4e2e11e into reduxjs:4.x Apr 16, 2023
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.

2 participants