Objeto de estrechamiento de mecanografiado
type Fish = { swim: () => void };
type Bird = { fly: () => void };
function move(animal: Fish | Bird) {
if ("swim" in animal) { // in operator narrowing
return animal.swim();
}
return animal.fly();
}
Stupid Scarab