codethrasher

Variadic Tuple Types

1
type Foo<T extends any[]> = [boolean, ...T, boolean]

Before TS@4.0 ...T would need to be the last element, but now we can spread the T type nested between known types; e.g. “This array will have a boolean, with some stuff (strings, numbers, etc.), and another boolean”.

← Composite Builds Labeled Tuple Types →