Concatenating Multiple Tuples
What you'll learn: How to combine two or more tuple types into a single tuple type that preserves the order and type of every element.
The Core Idea
When you have multiple tuple types and need to merge them into one larger tuple, TypeScript provides type-level operations to concatenate them while maintaining complete type safety. This is like joining arrays at runtime, but happening entirely at the type level.
Think of it like train cars: if you have one train with specific cargo in each car (a tuple), and another train with its own cargo arrangement, concatenating them means linking the trains together in order — preserving what's in each car and where it sits.
How Concatenation Works
You've already learned about variadic tuple types and spreading tuples in type positions. Concatenation builds on these concepts by spreading multiple tuples into a new tuple type:
type Tuple1 = [string, number];
type Tuple2 = [boolean, string];
// Concatenate by spreading both tuples
type Combined = [...Tuple1, ...Tuple2];
// Result: [string, number, boolean, string]
The spread operator ... unpacks each tuple's elements in order, and the surrounding square brackets collect them into a single new tuple.
Concatenating More Than Two Tuples
The pattern extends naturally to any number of tuples:
type A = [number];
type B = [string, boolean];
type C = [symbol];
type ABC = [...A, ...B, ...C];
// Result: [number, string, boolean, symbol]
Each tuple contributes its elements in the exact order you spread them.
Generic Concatenation
You can build reusable concatenation utilities using generics with tuple constraints:
type Concat<T extends readonly unknown[], U extends readonly unknown[]> = [...T, ...U];
type Result = Concat<[1, 2], [3, 4]>;
// Result: [1, 2, 3, 4]
This accepts any two tuple types and produces their concatenation, preserving literal types and element order.
Key Takeaway: Concatenating tuples uses the spread operator ... in type positions to merge multiple tuple types into one, preserving every element's type and position — essential for building complex type-level tuple manipulations.