reselect
reselect copied to clipboard
[Typescript] passing the same input selectors types breaks type inference
In the following example, the type of stringArray1 is correctly inferred as string[]
const test = createSelector( [ (state) => ['abc', 'def'] ], (stringArray1) => {
} )
however, if I add another string array
const test = createSelector(
[
(state) => ['abc', 'def'],
(state) => ['123', '456']
],
(stringArray1, stringArray2) => {
}
)
Both stringArray1 & stringArray2 are now typed as any.
If I change the second input function to return a number, both params are now typed properly again:
const test = createSelector(
[
(state) => ['abc', 'def'],
(state) => 100
],
(stringArray1, num) => {
}
)
Seems to only be an issue with the array of selectors. This properly infers types:
const test = createSelector(
(state) => ['abc', 'def'],
(state) => ['abc', 'def']
,
(stringArray1, stringArray2) => {
}
)
Is there any functional difference between the two?
No, and if I recall correctly the non-array version was introduced for typescript compatibility.