Does a class NEED a constructor in Typescript?

Just to extend the accepted answer and correct an answer by Jon Gear (TS might have changed in the meantime): Derived class does not need to create a constructor with the sole purpose to call super().

https://stackblitz.com/edit/no-need-for-derived-constructor?file=index.ts


Correct. Classes in TypeScript do not require you to explicitly write a constructor. However if you are extending a base class you will need to create a constructor to call super() at a minimum.


From the spec, section 8.3 (8.3):

A class may contain at most one constructor declaration. If a class contains no constructor declaration, an automatic constructor is provided, as described in section 8.3.3. (8.3.3.)

Tags:

Typescript