Swapped instanceof Branches
instanceof narrows the class correctly, but the branches call the wrong methods.
Codetypescript
class Dog { bark() { return "woof"; } }
class Cat { meow() { return "meow"; } }
function speak(animal: Dog | Cat) {
if (animal instanceof Dog) {
return animal.meow();
} else {
return animal.bark();
}
}What is the bug in this narrowing logic?