TS2391

error TS2391: Function implementation is missing or not immediately following the declaration.

Broken Code ❌

1
2
3
4
abstract class Animal {
abstract name: string;
makeNoise(): string;
}

Fixed Code ✔️

An abstract class is different from an interface. You have to use the abstract modifier if you want to define a contract in an abstract class. If there is no abstract modifier you will have to provide a implementation.

Solution 1:

To solve the problem, we can mark makeNoise with the abstract keyword. That will enforce derived classes to implement this method on their own:

1
2
3
4
abstract class Animal {
abstract name: string;
abstract makeNoise(): string;
}

Solution 2:

Another solution is to provide a base implementation for makeNoise:

1
2
3
4
5
6
abstract class Animal {
abstract name: string;
makeNoise(): string {
return 'Woof';
}
}

Video Tutorial