Course contentsShow
← TypeScript
Lesson 1378 of 1,79632. Advanced PatternsFree lesson

Tuple Destructuring Types

How TypeScript types destructured variables from tuple assignments.

Tuple Destructuring Types

What you'll learn: How TypeScript automatically infers accurate types when you destructure values from tuple types.

The Core Idea

When you destructure a tuple in TypeScript, the compiler preserves the exact types from each position. Unlike array destructuring (which gives all elements the same type), tuple destructuring gives each variable the specific type from its corresponding tuple position.

// Tuple type: [string, number, boolean]
const user: [string, number, boolean] = ["Alice", 30, true];

// Destructuring preserves position-specific types
const [name, age, isActive] = user;
// name is string
// age is number  
// isActive is boolean

How It Works

TypeScript maps each destructured variable to its tuple index. The first variable gets the type at index [0], the second gets [1], and so on:

type Point = [number, number];
const coords: Point = [10, 20];

const [x, y] = coords;
// x: number (from index 0)
// y: number (from index 1)

With mixed types, this precision becomes invaluable:

type Response = [boolean, string];
const result: Response = [true, "Success"];

const [success, message] = result;
// success: boolean
// message: string

With Optional Elements

When tuples have optional elements, destructured variables reflect that optionality:

type Metadata = [string, number?];
const data: Metadata = ["Item"];

const [item, count] = data;
// item: string
// count: number | undefined

With Rest Elements

Rest syntax in destructuring works with tuple rest elements:

type Triple = [number, number, ...number[]];
const values: Triple = [1, 2, 3, 4, 5];

const [first, second, ...rest] = values;
// first: number
// second: number
// rest: number[]

Key Takeaway: TypeScript preserves each tuple position's specific type during destructuring, giving you precise, position-aware type safety rather than generic array types.