Untitled

mail@pastecode.io avatar
unknown
typescript
a month ago
690 B
1
Indexable
Never
interface FlyingBirds {
    fly(): void;
}

interface NonFlyingBirds {
    walk(): void
}

interface Bird {
    makeSound(): void;
    eat(): void;
}

class Penguin implements Bird, NonFlyingBirds {
    walk(): void {
        console.log('I\'m walking');
    }

    eat(): void {
    }

    makeSound(): void {
    }
}

class Duck implements Bird, FlyingBirds{
    fly(): void {
        console.log('I\'m flying');
    }

    eat(): void {
    }

    makeSound(): void {
    }
}

function makeBirdFly(bird: FlyingBirds): void {
    bird.fly();
}

// Uso
const penguin = new Penguin();
const duck = new Duck();

penguin.walk();
duck.fly();


Leave a Comment