Skip to content

Instantly share code, notes, and snippets.

@vkurchatkin
Last active January 10, 2017 11:41
Show Gist options
  • Save vkurchatkin/d2e2f3cb0d83805f1399f85bd7cc27fb to your computer and use it in GitHub Desktop.
Save vkurchatkin/d2e2f3cb0d83805f1399f85bd7cc27fb to your computer and use it in GitHub Desktop.
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