TS2391

Function implementation is missing or not immediately following the declaration.

Broken Code ❌

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:

abstract class Animal {
  abstract name: string;
  abstract makeNoise(): string;
}

Solution 2:

Another solution is to provide a base implementation for makeNoise:

abstract class Animal {
  abstract name: string;
  makeNoise(): string {
    return 'Woof';
  }
}

Video Tutorial