-
-
Save vkurchatkin/d2e2f3cb0d83805f1399f85bd7cc27fb to your computer and use it in GitHub Desktop.
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
type Animal = | |
| { t: 'Cat' } | |
| { t: 'Dog' } | |
; | |
function makeSound(arr: Array<Animal>) { | |
for (const animal of arr) { | |
if (animal.t === 'Cat') { | |
console.log('meow'); | |
} else { | |
console.log('woof'); | |
} | |
} | |
} | |
const cats: Array<{ t: 'Cat' }> = [ | |
{ t: 'Cat' }, | |
{ t: 'Cat' }, | |
{ t: 'Cat' }, | |
]; | |
makeSound(cats); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment