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

Both functions test the same condition, but only one narrows. Why does `an2.bark()` fail to compile?

interface Animal { type: string } interface Dog extends Animal { type: "dog"; bark(): void } function isDog(a: Animal): a is Dog { return a.type === "dog"; } function looksDog(a: Animal): boolean { return a.type === "dog"; } declare const an2: Animal; if (looksDog(an2)) { an2.bark(); }