I am curious about how to effectively call this function in TypeScript. Can you guide me on the correct way to do it?
type Fish = { swim: () => void };
type Bird = { fly: () => void };
function move(animal: Fish | Bird) {
if ("swim" in animal) {
return animal.swim();
}
return animal.fly();
}
I attempted different methods like this:
move(Fish)
or even this:
move(swim)
Unfortunately, all my attempts resulted in an error.