You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Switch to Variadic Tuple Types for reducers and selectors #2715
But I'm hitting a problem where Typescript is not able to infer State properly, resulting in this error:
(in `router-store/src/router_selectors.ts)
Argument of type '(state: V) => RouterReducerState<any>' is not assignable to parameter of type 'Selector<unknown, RouterReducerState<any>>'.
Types of parameters 'state' and 'state' are incompatible.
Type 'unknown' is not assignable to type 'V'.
'V' could be instantiated with an arbitrary type which could be unrelated to 'unknown'.
As you can see, the type of createSelector has unknown as the type for state. Not sure why.
So the problem I was having in #2905 is that typescript doesn't seem to interpret variadic tuple type with strict order. It just creates a basic union type for all elements in the array.
This is problematic for createReducer as we want to have a function signature for a function that takes in a variadic number of selectors, followed by a single function whose parameters are all the return types of the reducers.
Instead, Typescript came up with a definition like this for the following:
typeNumberArray=number[];typeStringArray=string[];// I'd like a type that is a tuple of a variadic number of numbers followed by a variadic number of stringtypeCombined=[...numbers: NumberArray, ...strings: StringArray];functionthing(...args: Combined){return3;}thing('5',5);// this should result in an error, right?
...And now I see a comment from Alex in #2894 mentioning microsoft/TypeScript#41544 and that might be the fix needed to get the kind of type desired for createReducer
Activity
david-shortman commentedon Oct 27, 2020
I'm interested in helping add the types. Would want to know how I should go about this since the repo doesn't currently use 4.0+ yet.
markostanimirovic commentedon Dec 4, 2020
Issue with switching
createSelectorto variadic tuples: microsoft/TypeScript#41709david-shortman commentedon Jan 30, 2021
Here's at first shot at defining them.
But I'm hitting a problem where Typescript is not able to infer
Stateproperly, resulting in this error:(in `router-store/src/router_selectors.ts)
As you can see, the type of

createSelectorhasunknownas the type for state. Not sure why.david-shortman commentedon Jan 31, 2021
So the problem I was having in #2905 is that typescript doesn't seem to interpret variadic tuple type with strict order. It just creates a basic union type for all elements in the array.
This is problematic for
createReduceras we want to have a function signature for a function that takes in a variadic number of selectors, followed by a single function whose parameters are all the return types of the reducers.Instead, Typescript came up with a definition like this for the following:
A very simple example of my expectations vs reality:
playground
david-shortman commentedon Jan 31, 2021
...And now I see a comment from Alex in #2894 mentioning microsoft/TypeScript#41544 and that might be the fix needed to get the kind of type desired for
createReducerdavid-shortman commentedon Jul 2, 2021
Can we make a checklist of what still needs to be converted? Happy to help get items done.
feat(store): use variadic tuple types for createSelector (ngrx#3023)