Variadic tuples (TS 4.0). In tuple syntax a spread can name a type parameter: [...T, ...U] with T extends readonly unknown[]. When T is instantiated with a tuple, the spread flattens ([...[1, 2], ...[3]] is [1, 2, 3]); with an array it becomes a rest element ([...T] for number[] is number[]). Function signatures can therefore describe tuple transformations without overload ladders: concat, tail, partial(f, ...head), pipe, Promise.all-style mappers.
Inference. In the other direction, (...args: [...H, ...R]) => Out lets the checker split a parameter list: it infers H from the arguments you supplied and gives R the remaining parameters, keeping their labels. Writing a parameter as [...T] instead of T also hints that an array literal should be inferred as a tuple: [1, "a"] gives [number, string] rather than (string | number)[].
Rest anywhere (TS 4.2). [...string[], number] and [boolean, ...string[], boolean] are legal, with one rest element per tuple and no optional element after it (TS1265, TS1266).
Arithmetic. A tuple's "length" is a numeric literal type, so tuples act as unary numbers. Build a tuple of length N recursively, then:
- add:
[...Tuple<A>, ...Tuple<B>]["length"] - subtract:
Tuple<A> extends [...Tuple<B>, ...infer Rest] ? Rest["length"] : never - compare:
Ais at leastBexactly when the subtraction matches.
This only works for small non-negative integers. The builder is a recursive conditional type, so it hits the instantiation-depth limit described in the recursive-types question, and negative or fractional inputs never reach their target length (TS2589). It is a puzzle-and-library technique (fixed-length vectors, typed range), not something to put on a hot path in application code.