Skip to content

Instantly share code, notes, and snippets.

@Elijah-trillionz
Created June 10, 2022 17:41
Show Gist options
  • Save Elijah-trillionz/fa8db0973e1857ccaf50c203067d416e to your computer and use it in GitHub Desktop.
Save Elijah-trillionz/fa8db0973e1857ccaf50c203067d416e to your computer and use it in GitHub Desktop.
type annotations with "as" keyword
const animal: 'dog' | 'tiger' | 'lion' = 'dog';
const printDomesticAnimal = (animal: 'dog' | 'cat') => {
return animal;
}
printDomesticAnimal('tiger'); // bringing the tiger as tiger will be a problem
printDomesticAnimal('tiger' as 'dog'); // bringing the tiger as a dog
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment