the tswhy logo: a question mark in a box

tswhy‽

A community effort to enrich TypeScript diagnostics.

Editing TS1090:

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.

TS1090

'{0}' modifier cannot appear on a parameter.

Some modifiers can be added to constructor parameters in order to automatically declare the parameter as an element of the class. If you try to use an invalid modifier, this error will occur:

class A {
  constructor(static param: string) {}
}

Fix: Refactor code to remove modifier.

Replace the modifier with the explicit code you were hoping TypeScript would generate.

class A {
  static param: string = "";

  constructor(param: string) {
    A.param = param;
  }
}