reselect icon indicating copy to clipboard operation
reselect copied to clipboard

[Typescript] passing the same input selectors types breaks type inference

Open ChuckJonas opened this issue 9 years ago • 2 comments

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) => {

  }
)

ChuckJonas avatar Oct 05 '17 18:10 ChuckJonas

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?

ChuckJonas avatar Oct 05 '17 18:10 ChuckJonas

No, and if I recall correctly the non-array version was introduced for typescript compatibility.

ellbee avatar Oct 19 '17 19:10 ellbee