In TypeScript the keywords constructor and new for member declarations are used to declare constructors in classes and interfaces respectively. However, by using the wrong keyword a programmer can accidentally declare e.g. a method called constructor inside an interface. Similarly the keyword function is used to declare functions in some contexts, however, using the keyword function inside a class or interface results in declaring a method called function.

Declare classes as classes and not as interfaces. Use the keyword constructor to declare constructors in a class, use the keyword new to declare constructors inside interfaces, and don't use function when declaring an interface that is a function.

The below example declares an interface Point with 2 fields and a method called constructor. The interface does not declare a class Point with a constructor, which was likely what the developer meant to create.

The below example is a fixed version of the above, where the interface is instead declared as a class, thereby describing the type the developer meant in the first place.

  • TypeScript specification: Constructor Type Literals
  • TypeScript specification: Constructor Parameters