Skip to content
Quiz · Narrowing · lesson 12 of 12

Quiz — a wrong check

What does tsc say, and what happens when the program runs?

TypeScript
type Cat = { meow: string };
type Dog = { bark: string };

function isCat(pet: Cat | Dog): pet is Cat {
    return "bark" in pet;
}
function speak(pet: Cat | Dog) {
    if (isCat(pet)) {
        console.log(pet.meow.toUpperCase());
    }
}
speak({ bark: "woof" });