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
Inferring rest of array in a conditional results in unknown[]Β #45281
changed the title [-]Infering rest of array in a conditional results in `unknown[]`[/-][+]Inferring rest of array in a conditional results in `unknown[]`[/+]on Aug 2, 2021
Not only the rest of the array is misinferred, but any element as well:
typeFoobar<Textendsstring[]>=Textends[infer F, ...infer R]
? [`${F}`, `${R[0]}`]
: never// Type 'F' is not assignable to type 'string | number | bigint | boolean | null | undefined'.// Type 'R[0]' is not assignable to type 'string | number | bigint | boolean | null | undefined'.// Type 'unknown' is not assignable to type 'string | number | bigint | boolean | null | undefined'.
Activity
[-]Infering rest of array in a conditional results in `unknown[]`[/-][+]Inferring rest of array in a conditional results in `unknown[]`[/+]cypherfunc commentedon Mar 31, 2022
Has there been any movement on this?
The example can be simplified further, if it helps:
I've been able to get around this by adding an extra conditional check, but it's awkward/confusing in the middle of more complex types:
nag commentedon Jun 6, 2022
Not only the rest of the array is misinferred, but any element as well:
cypherfunc commentedon Jun 8, 2022
For any future folks, this is now easily solved with constraints in 4.7:
https://devblogs.microsoft.com/typescript/announcing-typescript-4-7/#extends-constraints-on-infer-type-variables