Array types T[]
T[] is the type of an array whose items are all of type T.
T[] reads as "an array of T". number[] is an array of numbers and string[] is an array of strings. If the array is called todos and each item is a Todo, you write Todo[].
The type checker uses it to check three things: what you put in the array, what you take out, and which methods you call. If you try to store a string in a number[], tsc refuses. And when you loop over the array, each item already has the right type.
The type only exists while tsc checks. When Node runs the code, the annotation is gone and you have a plain JavaScript array.
In the course you see it in lessons like 01.11: #todos: Todo[]; means "an array of Todo". That way the class knows what its list holds.
const names: string[] = ["Ana", "Luis"];
Reach for it when: a variable, property, parameter or return value is a list of values of the same type.
Examples
Common mistake
const ages: number[] = [20, 30];
ages.push("40");Why: The array only accepts numbers and `"40"` is a string. tsc catches it before you run.
How to write it: Pass a number: ages.push(40), or convert the value with Number("40").
