奇妙2. Type Predicate Union type(A または B、 A | B)のいずれかである ことを表せる特別なbooleanみたいなもの function isFish(pet: Fish | Bird): pet is Fish { return (pet).swim !== undefined; } let pet = getSmallPet(); if ((pet).swim) { (pet).swim(); } else { (pet).fly(); } if (isFish(pet)) { pet.swim(); } else { pet.fly(); } キャスト必要 キャスト不要 Type predicateを返すfunction=Type Guard