75 shaares
type Duck = {
type: "duck"
quack(): string
beAlive(): void
}
type Sheep = {
type: "sheep"
beeh(): string
beAlive(): void
}
function animalNoise(animal: Duck | Sheep) {
animal.beAlive()
animal.quack()
animal.beeh()
if (animal.type === "duck") {
animal.quack()
animal.beeh()
}
if (animal.type === "sheep") {
animal.quack()
animal.beeh()
}
}