DEV Community

Introduction to TypeScript Data Types — Tuple, Enum, and Any

John Au-Yeung on January 17, 2020

Subscribe to my email list now at http://jauyeung.net/subscribe/ Follow me on Twitter at https://twitter.com/AuMayeung Many more articles at http...
Collapse
 
itsjzt profile image
Saurabh Sharma

Tuple Vs Array was the most confusing thing in typescript for me.

Collapse
 
aumayeung profile image
John Au-Yeung

A tuple is like an array but it's fixed length and has no array methods. Also, the type of each entry is fixed.

Collapse
 
itsjzt profile image
Saurabh Sharma

Yeah I it now, but the syntax don't make very clear.

Thread Thread
 
aumayeung profile image
John Au-Yeung

Yea. It's better for it to not look like an array.

They probably just have to define tuples that way because it's an extension to JavaScript, so they can't define their own syntax.

Collapse
 
patarapolw profile image
Pacharapol Withayasakpunt

How is Enum interop with JavaScript? Why not String with predefined values?

Collapse
 
aumayeung profile image
John Au-Yeung

It's just converted back to the usual JavaScript data types depending on the value you assigned the enum to.