简体   繁体   English

TypeScript中的类型化数组 - Array <Foo>和Foo []之间的区别是什么?

[英]Typed arrays in TypeScript - what is the difference between Array<Foo> and Foo[]?

In TypeScript I have a class Foo 在TypeScript中,我有一个类Foo

class Foo {}

I want array of instances of Foo. 我想要Foo的实例数组。 What is the difference between 有什么区别

var foos : Array<Foo>;

and

var foos : Foo[];

It seems to me that both define array of instances of given type, is there any difference at all? 在我看来,两者都定义给定类型的实例数组,是否有任何区别?

EDIT: What are the names of these constructs? 编辑:这些结构的名称是什么? How do I correctly refer to them? 我该如何正确引用它们?

They are both identical as type annotations, so you can use whichever you prefer. 它们与类型注释相同,因此您可以使用您喜欢的任何一种。

The Array syntax has only been available since generics were added. 自添加泛型以来,Array语法才可用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM