Skip to content

Instantly share code, notes, and snippets.

@hw0k
Last active January 17, 2021 09:23
Show Gist options
  • Save hw0k/dce65c2162f98ad48e329b06f8eab557 to your computer and use it in GitHub Desktop.
Save hw0k/dce65c2162f98ad48e329b06f8eab557 to your computer and use it in GitHub Desktop.
TN 1
class Dog {
bark = () => {
console.log('bark!');
};
}
class Cat {
meow = () => {
console.log('meow!');
};
}
function sound(animal: Dog | Cat) {
if (animal instanceof Dog) {
animal.bark();
animal.meow();
return;
}
if (animal instanceof Cat) {
animal.bark();
animal.meow();
return;
}
animal.bark();
animal.meow();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment