typescript TypeGuard
class Animal {
}
class Duck extends Animal {
}
class Tiger extends Animal {
}
const isDuck = (animal: Animal): animal is Duck =>
animal.type === 'duck' && animal.call !== undefined
const animal = someFunc()
if (isDuck(animal)) {
animal.call()
}