In TypeScript, certain keywords have special meanings for member declarations, and misusing them can create confusion:

When these keywords are misused, TypeScript will interpret them as regular method names rather than their intended special syntax, leading to code that may not work as expected.

Consider following these guidelines for clearer code:

The following examples show common mistakes when using these keywords:

This interface mistakenly uses constructor, which creates a method named "constructor" instead of a constructor signature:

Use new for constructor signatures in interfaces:

This class mistakenly uses new, which creates a method named "new" instead of a constructor:

Use constructor for constructors in classes:

This interface uses function as a method name, which declares a method named "function" rather than declaring a function:

Use a descriptive method name instead:

  • TypeScript Handbook: Classes - Constructors.
  • TypeScript specification: Constructor Type Literals.
  • TypeScript specification: Constructor Parameters.