Skip to content

Instantly share code, notes, and snippets.

View Elijah-trillionz's full-sized avatar
💭
hacking

Elijah Trillionz Elijah-trillionz

💭
hacking
View GitHub Profile
@Elijah-trillionz
Elijah-trillionz / annotations.ts
Created June 10, 2022 17:41
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