TS2377
error TS2377: Constructors for derived classes must contain a ‘super’ call.
Broken Code ❌
1 2 3 4 5 6 7 8 9 10 11
| abstract class Animal { abstract name: string; }
class Dog extends Animal { public name;
constructor(name: string) { this.name = name; } }
|
Fixed Code ✔️
Every constructor
in a derived class has to call the super
method to invoke the constructor
of the base class. It has to be the very first call:
1 2 3 4 5 6 7 8 9 10 11 12
| abstract class Animal { abstract name: string; }
class Dog extends Animal { public name;
constructor(name: string) { super(); this.name = name; } }
|
Video Tutorial