Mastering Typed Arrays
Annotation and Inference
// TypeScript reads the contents of this array and infers the type
const carMakers = ['Ford', 'Toyota'];const carMakers: string[] = [];
// Logic to add car makers here...Annotating two-dimensional arrays
const carsByMake: string[][] = [['F150'], ['Corolla'], ['Camaro']];Why Typed Arrays Matter
const carMakers: string[] = ['Ford', 'Toyota'];
// TypeScript knows these variables will be a string
const firstCar = carMakers[0];
const lastCar = carMakers.pop();Multiple Types in Arrays
Last updated