Guided Notes

Arrays & Tuples

Typed arrays, readonly arrays, array methods with types, tuples for fixed-length data, named and optional tuple elements, and destructuring.

Typed arrays

Slide 1 / 4

const scores: number[] = [72, 88, 95]; const names: Array<string> = ["Ana", "Ben"]; // same thing, generic syntax

scores.push("A+"); // error: string is not assignable to number

Array methods keep their types: scores.map(s => s / 100) is number[], names.filter(n => n.startsWith("A")) is string[]. TypeScript infers the element type from the initial values.

← Simple & Special Types