To specify the type of an array like
[1, 2, 3]
, you can use the syntaxnumber[];
this syntax works for any type (e.g.string[]
is an array of strings, and so on). You may also see this written asArray<number>
, which means the same thing. We'll learn more about the syntaxT<U>
when we cover generics.Note that
[number]
is a different thing; refer to the section on Tuples.
—
The TypeScript Handbook: Everyday Types