12

In TypeScript I have a class Foo

class Foo {}

I want array of instances of 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?

1 Answer 1

14

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.

Sign up to request clarification or add additional context in comments.

2 Comments

I have edited the question a bit - do you happen to know what are the names of these constructs? How do I correctly refer to them?
The square brackets are an 'array literal' and the <T> version is a 'generic type with a type argument' - although in this case they are both 'type annotations' too.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.