Fungsi TypeScript Type Guard

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