Fonction de garde de type dactylographié
type Fish = { swim: () => void };
type Bird = { fly: () => void };
function isFish(pet: Fish | Bird): pet is Fish {
return (pet as Fish).swim !== undefined;
}
const myFish: Fish | Bird = { swim: () => {} };
isFish(myFish) && myFish.swim();
Dead Dormouse