Skip to content

Instantly share code, notes, and snippets.

@s1rat-dev
Created February 20, 2022 00:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save s1rat-dev/916f7b4ad1fbb2632b4534432f6650c2 to your computer and use it in GitHub Desktop.
Save s1rat-dev/916f7b4ad1fbb2632b4534432f6650c2 to your computer and use it in GitHub Desktop.
[TYPESCRIPT] Annotations for tuples.
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