TypeScript Academy · Lesson

Tuples & labeled tuples

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

Lesson 2 of 38 steps

Tuples & labeled tuples is a free TypeScript Academy lesson on CoddyKit. This is 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, and your progress syncs across the web and the CoddyKit app. The TypeScript Academy course includes 3 lessons in total.

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.

Free to start

Learn TypeScript with an AI tutor — free

Write and run real code in your browser, get instant help from a 24/7 AI tutor, and pick up where you left off on the web or in the app.

Courses
101
Lessons
352

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. 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. The TypeScript Academy course includes 3 lessons in total.

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, so you can start here or from the beginning and move at your own pace. This is lesson 2 of 3.

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