What is the difference Array<string> and string[]?

Typescript

Typescript Problem Overview


Whats is the difference between Array<string> and string[]?

var jobs: Array<string> = ['IBM', 'Microsoft', 'Google'];
var jobs: string[]      = ['Apple', 'Dell', 'HP'];

Typescript Solutions


Solution 1 - Typescript

There's no difference between the two, it's the same.

It says this in the docs:

> Array types can be written in one of two ways. In the first, you use > the type of the elements followed by [] to denote an array of that > element type:

let list: number[] = [1, 2, 3];

> The second way uses a generic array type, Array:

let list: Array<number> = [1, 2, 3];

You do need to use the Array<T> form when you want to extend it for example:

class MyArray extends Array<string> { ... }

but you can't use the other form for this.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSajith MantharathView Question on Stackoverflow
Solution 1 - TypescriptNitzan TomerView Answer on Stackoverflow