Skip to main content

How does string[] differ from Array<string>?

1. The main difference

NotationWhat it meansEquivalent
string[]"an array of strings"Array<string>
Array<string>"an array of elements of type string (via a generic)"string[]

So both forms mean exactly the same thing: an array of strings. The only difference is in syntax and readability.


Example 1 - equivalent declarations

javascript
const a: string[] = ["a", "b", "c"]; const b: Array<string> = ["a", "b", "c"];

Both arrays are identical in type and behavior. The TypeScript compiler sees no difference between them.


2. When string[] is better, and when Array<string> is

string[] - simpler and shorter

Used in 90% of cases, when the type is a primitive or a simple object.

javascript
const nums: number[] = [1, 2, 3]; const names: string[] = ["Tim", "Max"];

Array<Type> - more convenient for complex types

When the inner type is a generic, a union, an intersection, or a function:

javascript
type User = { id: number; name: string }; const users: Array<User> = [ { id: 1, name: "Tim" }, { id: 2, name: "Max" }, ];

or

javascript
const mixed: Array<string | number> = ["a", 1, "b", 2];

Here Array<string | number> reads a little easier than (string | number)[].


Example with a complex function type

javascript
type Callback = () => void; const callbacks1: Callback[] = []; const callbacks2: Array<Callback> = []; callbacks1.push(() => console.log("ok")); callbacks2.push(() => console.log("ok"));

Both variants work the same way, but Array<Callback> can be a bit clearer if the type is long.


3. Technically, T[] is just "syntactic sugar"

Internally, TypeScript treats both forms the same way. They are two ways of writing the same generic definition:

javascript
T[] === Array<T>

T[] is the short notation, Array<T> is the full generic-type notation.


4. Special cases: ReadonlyArray

If you use immutable arrays, Array<T> gives you more options.

javascript
const arr: ReadonlyArray<number> = [1, 2, 3]; arr.push(4); // Error

For readonly number[] and ReadonlyArray<number> the behavior is the same, but ReadonlyArray can be conveniently combined with generics:

javascript
function freeze<T>(arr: ReadonlyArray<T>): void {}

5. Example with multidimensional arrays

Both forms are equivalent and read differently:

javascript
const matrix1: number[][] = [[1, 2], [3, 4]]; const matrix2: Array<Array<number>> = [[1, 2], [3, 4]];

Here number[][] is visually simpler, while Array<Array<number>> is more formal.


Summary

Comparisonstring[]Array<string>
Brevityshorterlonger
Convenient for complex typesmediumreads better
Support for generic functionsyesyes
Semanticsidenticalidentical
Frequency of usevery highless common (more formal style)

Rule of thumb:

  • For simple cases - T[] (string[], number[], User[])
  • For complex generic types - Array<T> (Array<User | Admin>, Array<() => void>)

Short Answer

Interview ready
Premium

A concise answer to help you respond confidently on this topic during an interview.