-
Notifications
You must be signed in to change notification settings - Fork 47
Open
Description
When destructured typing is used with rest elements in the middle, the last variable is not typed currently (0.11.0)
This for example can cause a TS error when the number of elements does not match in tuple types.
Input
[first:: string, ...rest:: number[], last:: string] := list
Expected Output
const [first, ...rest]: [string, ...number[], string] =
list,
[last] = rest.splice(-1);Current Output
const [first, ...rest]: [string, ...number[]] =
list,
[last] = rest.splice(-1);Notes about types
In the above example rest becomes [...number[], string] — essentially equals to (string | number)[] instead of number[] — and last will be string | number | undefined.
Meaning typing last will not just be incorrect itself, but also screw up the types for rest too.
TS itself is problematic with extracting the types from tuples like this.
Metadata
Metadata
Assignees
Labels
No labels