💡
This article is a part of TypeScript Unlocked Series on my blog. Every article in the series is short, crisp and filled with examples and code snippets. If you want to learn TypeScript from scratch for absolutely FREE!!! check it out.
Tuple is TypeScript Specific thing and we don’t have tuples in JavaScript. Tuples allow us to enforce order of types in an array.
let UserTuple: [number,string,boolean]
UserTuple = [122,”Palash”,true]
UserTuple = [122,”Palash”,”true”]
We can define tuples using type as well
type UserTuple = [number,string,boolean]
let UserTuple2: UserTuple = [122,”Palash”,true]
let UserTuple3: UserTuple = [122,”Palash”,”true”]
Bad behavior
Tuple has some bad behavior which it should not do but it is allowed anyways.
let UserTuple: UserTuple = [122,”Palash”,true]
UserTuple.push(“tf”)
if you reached till here and you liked what you read don’t forget LIKE to SHARE it with other people. if you have any feedback or suggestions feel free to use the comment section. Hope you tag along till the end of this series and strengthen your coding armor by adding TypeScript to it. Happy coding!
Source: hashnode.com