TS2720

error TS2720: Class ‘Dog‘ incorrectly implements class ‘Animal‘. Did you mean to extend ‘Animal‘ and inherit its members as a subclass? Property ‘makeNoise‘ is protected but type ‘Dog‘ is not a class derived from ‘Animal‘.

Broken Code ❌

1
2
3
4
5
6
7
8
9
abstract class Animal {
protected abstract makeNoise(): string;
}

class Dog implements Animal {
protected makeNoise(): string {
return 'Woof!';
}
}

Fixed Code ✔️

The implements keyword is reserved to implement interfaces. If you want to work with class inheritance, you have to use extends:

1
2
3
4
5
6
7
8
9
abstract class Animal {
protected abstract makeNoise(): string;
}

class Dog extends Animal {
protected makeNoise(): string {
return 'Woof!';
}
}

Video Tutorial