Array Type Syntax: T[] vs Array<T>
What you'll learn: TypeScript offers two completely equivalent ways to type arrays, and you'll learn when to use each.
The Two Syntaxes
When you want to tell TypeScript "this is an array of numbers" or "this is an array of strings," you have two choices that mean exactly the same thing:
// Syntax 1: T[]
let scores: number[] = [10, 20, 30];
let names: string[] = ["Alice", "Bob"];
// Syntax 2: Array<T>
let scoresAlt: Array<number> = [10, 20, 30];
let namesAlt: Array<string> = ["Alice", "Bob"];
Both pairs above are completely interchangeable. TypeScript treats number[] and Array<number> as identical types.
Which Should You Use?
The T[] syntax (like number[]) is more common in the TypeScript community because it's:
- Shorter and faster to type
- Easier to read at a glance
- The default in most codebases
The Array<T> syntax (like Array<number>) is preferred when:
- You're already using similar generic syntax elsewhere
- You have very complex types where brackets get confusing
- Your team has a style guide requiring it
Think of It Like Spelling
This is like "grey" vs "gray" — both are correct, both mean the same thing. Pick one style and stick with it consistently in your code. Most developers default to T[] for simplicity.
// Both work identically
let flags: boolean[] = [true, false];
let flagsAlt: Array<boolean> = [true, false];
Key Takeaway: T[] and Array<T> are two ways to write the same array type — prefer T[] for simplicity unless you have a specific reason to use the generic form.