Spreading Tuples in Type Positions
What you'll learn: How to use the spread operator (...) with tuple types to compose and build complex tuple shapes at the type level.
The Core Concept
Just as you can spread arrays in JavaScript ([...arr1, ...arr2]), TypeScript allows you to spread tuple types using the same ... syntax in type positions. This lets you combine multiple tuple types into a single, larger tuple type — merging their elements in order while preserving exact positions and types.
Think of it like arranging train cars: if you have one train segment [Engine, Passenger] and another [Cargo, Caboose], spreading them creates [Engine, Passenger, Cargo, Caboose] — a single train with all cars in sequence.
How It Works
When you spread a tuple type inside another tuple type, TypeScript "unpacks" all the elements:
type Start = [string, number];
type End = [boolean];
// Spread Start's elements, then End's elements
type Combined = [...Start, ...End];
// Result: [string, number, boolean]
You can mix spreads with explicit elements:
type Prefixed = [0, ...Start];
// Result: [0, string, number]
type Sandwiched = [...Start, null, ...End];
// Result: [string, number, null, boolean]
Generic Tuple Composition
Spreading becomes especially powerful with generics, letting you build flexible tuple transformers:
type Prepend<T extends any[], Item> = [Item, ...T];
type Append<T extends any[], Item> = [...T, Item];
type Numbers = [1, 2, 3];
type WithZero = Prepend<Numbers, 0>; // [0, 1, 2, 3]
type WithFour = Append<Numbers, 4>; // [1, 2, 3, 4]
This unlocks compositional patterns where you build complex tuple shapes from smaller pieces without manual element-by-element type construction.
Key Takeaway: Spreading tuples in type positions with ... lets you compose tuple types declaratively, combining multiple tuple segments into unified shapes — essential for advanced tuple manipulation patterns like prepending, appending, and merging typed parameter lists.