14

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?

1 Answer 1

18

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.

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

1 Comment

Which one is the sugar in this case? Any thoughts?

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.