mirror of
https://github.com/muerwre/muerwre.github.io.git
synced 2025-04-25 02:46:39 +07:00
277 B
277 B
Useful for type checking at compile and run time:
function isFish(pet: Fish | Bird): pet is Fish {
return (pet as Fish).swim !== undefined;
}
Usage:
const pet = getSmallPet();
if (isFish(pet)) {
pet.swim();
} else {
pet.fly();
}