the tswhy logo: a question mark in a box

tswhy‽

A community effort to enrich TypeScript diagnostics.

Editing TS1089:

All diagnostics and fixes are authored in markdown. Propose any changes by editing the markdown. Additional fixes can be added. A preview of the rendered diagnostic will update when changes are made.

Once all proposed changes are made, the Propose button will submit the information and confirm raising the PR.

TS1089

'{0}' modifier cannot appear on a constructor declaration.

Some modifiers cannot be applied to class constructors:

class A {
  static constructor()
  abstract constructor()
  async constructor()
  readonly constructor() {}
}

Static constructor methods cannot be named constructor as the constructor property already exists on objects and refer to the constructor of the object. create is a common alternative name. Similarly, async can be applied to a static "constructor". Marking a constructor as abstract doesn't make sense since abstract only refers to members of the instance of a class. Constructors cannot be assigned to, so readonly doesn't make sense.

Fix: undefined

Remove the constructor modifier:

class A {
  static create(): A;

  static async createAsync(): Promise<A>;

  constructor() {}
}