5

Typescript allows one to define an Array with either syntax:

var myStrArry1: string[] = [];

or

var myStrArry1: Array<string> = [];

The compiled output appears to be the same. Does the compiler treat them identically, or are there some quirks to be aware of?

1

3 Answers 3

4

Does the compiler treat them identically, or are there some quirks to be aware of?

They are identical. I prefer syntax 1

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

Comments

2

From the typescript documentation, they are treated identically, one is simply a shorthand notation for the other. The compiler doesn't care which one you use.

Comments

1

This is the paragraph from TypeScript specification: https://github.com/Microsoft/TypeScript/blob/master/doc/spec.md#3.8.4 that specifies that both syntaxes are equivalent:

Alternatively, array types can be written using the Array<T> notation. For example, the types above are equivalent to

Array<string | number> Array<() => string>

Comments

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.