Untitled
unknown
typescript
a year ago
690 B
8
Indexable
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();
Editor is loading...
Leave a Comment