Skip to main content
Journey Uncommon Logo
JourneyUncommon
mediumTypeScriptuser-defined type guardsSingle-choice MCQ

`isFish` is a user-defined type guard. What is the type of `pet` inside the `else` branch?

interface Fish { swim(): void } interface Bird { fly(): void } function isFish(p: Fish | Bird): p is Fish { return (p as Fish).swim !== undefined; } function move(pet: Fish | Bird) { if (isFish(pet)) { pet.swim(); } else { // pet here? } }