0Pricing
TypeScript Academy · Lesson

Tuples & labeled tuples

Learn about tuples: arrays with fixed length and known element types. Discover labeled tuples for readability.

Tuples & labeled tuples is a free TypeScript Academy lesson on CoddyKit — lesson 2 of 3. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the TypeScript Academy learning path, one of 3 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Intro

Goal: Learn how tuples differ from arrays. They have fixed length and element types, and can be labeled for clarity.

Simple tuple

A tuple defines specific element types at each position, unlike arrays where all elements share a type.

let point: [number, number] = [10, 20];
console.log(point[0], point[1]);

Tuple length

Tuples enforce fixed length. Assigning more or fewer elements causes errors.

let coords: [number, number] = [5, 6];
// coords = [5, 6, 7]; // Error: too many elements

Mixed types tuple

Tuples can hold different types in specific positions, like an ID, name, and active flag.

let user: [number, string, boolean] = [1, "Ada", true];

Labeled tuple

Labeled tuples make positions clearer, improving readability in function signatures and APIs.

type Point = [x: number, y: number];
const p: Point = [3, 4];

Guidelines

Guidelines:

  • Use tuples for fixed-structure data.
  • Prefer labels when meaning matters.
  • Stick to arrays for variable-length collections.

Tuple check

Quick check: What is a key feature of tuples compared to arrays?

Recap

Recap: Tuples enforce position-based types and lengths. Labeled tuples improve clarity. Arrays stay flexible, tuples give structure.

Frequently asked questions

Is the “Tuples & labeled tuples” lesson free?

Yes — the full text of “Tuples & labeled tuples” is free to read here on the web, and the TypeScript Academy course includes 3 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the TypeScript Academy course, upgrade to CoddyKit PRO.

What will I learn in “Tuples & labeled tuples”?

Learn about tuples: arrays with fixed length and known element types. Discover labeled tuples for readability. You practise TypeScript Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start TypeScript Academy?

No prior experience is required. TypeScript Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 3, so you can start here or from the beginning and move at your own pace.

How long does the “Tuples & labeled tuples” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this TypeScript Academy lesson?

Yes. Every TypeScript Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Arrays & ReadonlyArray
  2. Tuples & labeled tuples
  3. Enums vs const enum vs union-literal alternatives
← Back to TypeScript Academy