Skip to content
AgileLogics
4 min read

Arrays and Tuples

Prerequisites: Basic types

An array type describes a list where every element is the same type. A tuple describes a fixed-length list where each position has its own specific type.

let scores: number[] = [10, 20, 30];
let point: [number, number] = [3, 4]; // exactly 2 numbers

point = [3, 4, 5]; // Source has 3 element(s) but target allows only 2

Use an array type for "many of the same kind of thing," and a tuple for "exactly this fixed shape" — like a coordinate pair or a [key, value] entry.