Objet de rétrécissement de typeScript

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