TS2689

error TS2689: Cannot extend an interface ‘Animal’. Did you mean ‘implements’?

Bad Code ❌

1
2
3
4
5
6
7
interface Animal {
name: string;
}

class Dog extends Animal {
name = 'Default Dog';
}

Fixed Code ✔️

The TypeScript compiler tells us already the solution: When implementing an interface, we have to use implements. If we inherit from classes, we use extends.

1
2
3
4
5
class Dog extends Animal {
protected makeNoise(): string {
return "Woof!";
}
}