Created
February 20, 2022 00:56
-
-
Save s1rat-dev/916f7b4ad1fbb2632b4534432f6650c2 to your computer and use it in GitHub Desktop.
[TYPESCRIPT] Annotations for tuples.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const drink = { | |
color: 'brown', | |
carbonated: true; | |
sugar: 40 | |
} | |
// Creating tuple type. | |
// Used when we want to know what are any value of array. | |
// Easy way to sorting as value. | |
type Drink = [string, boolean, number]; | |
const pepsi: Drink = ['brown', true, 40]; | |
const sprite: Drink = ['clear', true, 40]; | |
const tea: Drink = ['brown', false, 0]; | |
// But sometimes Tuples can be too complex to understand. | |
// For example as follow, we don't know what mean those numbers. | |
const carSpecs: [number, number] = [400,3453] | |
const carStats = { | |
horsePower: 400, | |
weight: 3354 | |
} | |
// So in like that cases, | |
// we can use Objects instead of Tuples. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment