Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Type Script: Array<Object> vs Object[]

In Typescript what is the difference between these assignments:

var Object[];
var Array<Object>

Does generics in Type Script has the same semantic meaning as in languages like Java or is it simply syntactic sugar?

like image 504
Shikloshi Avatar asked Nov 04 '15 16:11

Shikloshi


1 Answers

It's just sugar. Object[] and Array<Object> are exactly the same in TypeScript.

One way to check this is to write this code:

var x: Object[];
var x: Array<Object>;

Duplicate variable declarations must have exactly the same type, so the lack of error here implies that the types are identical.

like image 67
Ryan Cavanaugh Avatar answered Sep 22 '22 13:09

Ryan Cavanaugh