Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Typescript2: Array<any> and Array<Object> difference

Tags:

typescript

Which is the difference between declaring a field as Array<any> and Array<Object>.

Is there some extra collection tools in typescript?

like image 358
Jordi Avatar asked Feb 05 '23 13:02

Jordi


1 Answers

An Object in TypeScript is the same thing as in JavaScript.

The difference is that any accepts primitives as well: a number is not an object, unless boxed to a Number.

So while an Array<any> can contain primitives, an Array<Object> can't.

TL;DR: don't use Object.

Source: TypeScript's Do's and Don'ts

like image 155
Ven Avatar answered Feb 16 '23 00:02

Ven