Skip to main content
Brave Programmer Logo

BraveProgrammer

BraveProgrammer

HomeProjectsBlogsCoursesLessonsAbout

Site footer

BraveProgrammer

Free coding courses, practical tutorials, and real projects from BraveProgrammer. Learn web development with React, Next.js, and TypeScript.

Navigation

  • Home
  • Projects
  • Blogs
  • Courses

Resources

  • About
  • Lessons

© 2026 BraveProgrammer. All rights reserved.

  1. Courses
  2. /
  3. TypeScript Mastery

Lesson 15 of 56 · Typescript

Tuples & ReadonlyArray

Duration: 20 minutes

Tuple Types

A tuple expresses a fixed‑length array with known element types.

let point: [number, number] = [10, 20];
// Access by index with proper types
let x = point[0]; // number

Optional Elements & Rest Elements

type Request = [method: string, url: string, body?: any];
let req1: Request = ["GET", "/users"];
let req2: Request = ["POST", "/users", { name: "Bob" }];

ReadonlyArray<T>

const nums: ReadonlyArray<number> = [1, 2, 3];
// nums.push(4); // ❌ error – read‑only

Spread with Tuples

function concat<T extends unknown[], U extends unknown[]>(...args: [...T, ...U]): [...T, ...U] {
  return args as any;
}

Info

Tuples are heavily used for function argument lists and variadic generic patterns.

Previous: Type Guards & Discriminated UnionsNext: Recursive Types