Typed Arrays: T[] and Array<T>
Type arrays and prevent mixing incompatible values.
Welcome
TypeScript lets you type arrays so that only values of a specific type can be stored. This lesson covers the two syntax forms and their use cases.
The T[] Syntax
The most common way to type an array is to append [] to the element type. This is called the shorthand syntax.
const numbers: number[] = [1, 2, 3];
const names: string[] = ['Alice', 'Bob'];
const flags: boolean[] = [true, false, true];All lessons in this course
- Typed Arrays: T[] and Array
- Readonly Arrays and Immutable Data
- Tuples: Fixed-Length Typed Arrays
- Enums: Numeric and String Constants