0Pricing
TypeScript Academy · Lesson

Rest Parameters and Spread with Types

Type rest parameters and spread operations.

Welcome

Rest parameters collect multiple arguments into an array. TypeScript types the rest parameter as an array of the element type.

Typing Rest Parameters

Use `...name: T[]` syntax for a rest parameter. It captures all remaining arguments as an array.
function sum(...nums: number[]): number {
  return nums.reduce((a, b) => a + b, 0);
}
console.log(sum(1, 2, 3, 4)); // 10

All lessons in this course

  1. Parameter and Return Type Annotations
  2. Optional and Default Parameters
  3. Rest Parameters and Spread with Types
  4. void, never, and Function Signatures
← Back to TypeScript Academy