📌  相关文章
📜  在打字稿代码示例中验证对象是否属于某种类型

📅  最后修改于: 2022-03-11 14:48:19.651000             🧑  作者: Mango

代码示例2
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();
}