📅  最后修改于: 2022-03-11 14:48:19.651000             🧑  作者: Mango
function isFish(pet: Fish | Bird): pet is Fish {
return (pet).swim !== undefined;
}
// Both calls to 'swim' and 'fly' are now okay.
if (isFish(pet)) {
pet.swim();
}
else {
pet.fly();
}