TypeScript: How to use Tuples in TypeScript

in #typescript5 years ago

Learn How to use Tuples in TypeScript.

If you like this video then Do share the video in the article to your friends or in your social media accounts. You can also subscribe to the YouTube channel.

Check out the video above to learn How to use Tuples in TypeScript.

I recommend checking out Learning Typescript book. You can get a lot of answers to your questions. Plus the new edition of the book can cover some of the latest topics too.

How to use Tuples in TypeScript Examples

So what are tuples? And why do we even bother to invent something like this? The reason behind that is arrays are used to group the objects of similar data types. In such case adding string and numbers would require you to have different collection instead of arrays. So in such case the tuples can be used as well.

Here's the simple syntax of the tuple.

var tuple_name = [value1,value2,value3,…value n]

You have to specify the var and then followed by the tuple name and then keep on adding the mixed data type values in square bracket. You can check out the sample below for code that works as a tuple.

var mytuple =  [10,"devnami"];

So now you get the idea what are tuples and how they work. You should definitely check the example live on above video.

So that's simple demo for you to check out. I recommend checking out Learning Typescript book. Let me know if you like the video.

I hope the information here helps you. I'd appreciate if you like the video and share it with others.

Coin Marketplace

STEEM 0.15
TRX 0.15
JST 0.028
BTC 53949.09
ETH 2223.84
USDT 1.00
SBD 2.31