What is the difference Array<string> and string[]?
TypescriptTypescript 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.