0Pricing
TypeScript Academy · Lesson

Spread in Arrays and Objects

Spread values while preserving accurate types.

Spreading Values

The spread operator ... copies elements of an array or properties of an object into a new one. TypeScript tracks the resulting type precisely, which is key for immutable updates.

Array Spread

Spread two arrays into a new one to concatenate them. The result's element type is the union of both source element types.

const a = [1, 2]
const b = [3, 4]
const all = [...a, ...b]
console.log(all) // [1, 2, 3, 4]

All lessons in this course

  1. Rest Parameters in Functions
  2. Spread in Arrays and Objects
  3. Tuple Rest Elements
  4. Typing Variadic Functions
← Back to TypeScript Academy