Lesson 4 / 26
Arrays & Tuples
Typed lists, and fixed-length, fixed-type tuples.
Typed arrays
number[] or Array<number> both mean "an array of numbers only".
let scores: number[] = [90, 85, 76];
let names: Array<string> = ["Ada", "Bo"];
scores.push("100");
// Error: Argument of type 'string' is not assignable to parameter of type 'number'.Tuples: fixed shape
A tuple is an array with a known length and a known type at each position.
let point: [number, number] = [10, 20];
let entry: [string, number] = ["age", 36];
entry = [36, "age"];
// Error: Type 'number' is not assignable to type 'string'.Array vs tuple
Use an array for a variable-length list of the same kind of thing; use a tuple when position carries meaning, like [key, value].