"Two syntaxes, one type. Pick whichever reads more naturally for the case."
The two ways to spell an array type
TypeScript supports two equivalent syntaxes for array types: T[] (shorthand) and Array<T> (generic form). They produce the same type — the choice is style.
const ages: number[] = [21, 18, 16]const ages: Array<number> = [21, 18, 16]
The shorthand reads naturally for simple element types: string[], number[], User[]. The generic form starts to win when the element type is itself a union or a complex compound: Array<string | number> reads more naturally than (string | number)[], where the parentheses are easy to misread.
Inference for array literals
TypeScript widens array element types from literals to their primitive parents by default:
['hi', 'there']infersstring[](not('hi' | 'there')[]).[1, 2, 3]infersnumber[].[1, 'two']infers(string | number)[]— the compiler unions the element types.
This widening is usually what you want. When you want the narrow inference, reach for as const (covered in lesson 5.4) or an explicit tuple annotation.
Array operations are typed
The whole Array prototype — map, filter, reduce, find, flat, etc. — has rich types in the standard library. The compiler tracks element types through chains. users.filter(u => u.active).map(u => u.email) on a User[] ends up as string[] automatically.
The one gotcha: methods that take a callback may need their generic explicit if the inference picks a wider type. Array.from(set) usually works, but for complex Iterable shapes you sometimes write Array.from<T>(iter).
T[] for simple element types and Array<T> when the element type is a union or compound expression. Stay consistent within a file.Multi-dimensional arrays
Stack the syntax for nested arrays. number[][] is an array of arrays of numbers. Array<Array<number>> is the same thing. For type readability, the shorthand is usually clearer for simple nesting; for complex nesting, you might extract a type alias.
Pippa's confession
T[] almost universally. The one place I switch to Array<T> is when T is a tagged union — Array<{ type: 'a'; payload: A } | { type: 'b'; payload: B }> reads better than the parenthesized shorthand. Otherwise, the shorthand is denser and easier to skim.