Suggest an editImprove this articleRefine the answer for “How does string[] differ from Array<string>?”. Your changes go to moderation before they’re published.Approval requiredContentWhat you’re changing🇺🇸EN🇺🇦UAPreviewTitle (EN)Short answer (EN)**`string[]`** and **`Array<string>`** are two equivalent ways to write an array of strings; TypeScript treats them identically. **Key point:** `T[]` is more convenient for simple types, while `Array<T>` reads better for generics, unions, or complex function types.Shown above the full answer for quick recall.Answer (EN)Image## 1. The main difference | Notation | What it means | Equivalent | |---|---|---| | `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 | Comparison | `string[]` | `Array<string>` | |---|---|---| | Brevity | shorter | longer | | Convenient for complex types | medium | reads better | | Support for generic functions | yes | yes | | Semantics | identical | identical | | Frequency of use | very high | less 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>`)For the reviewerNote to the moderator (optional)Visible only to the moderator. Helps review go faster.