the tswhy logo: a question mark in a box

tswhy‽

A community effort to enrich TypeScript diagnostics.

Editing TS1019:

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.

TS1019

An index signature parameter cannot have a question mark.

Unlike regular function parameters, index signature parameters cannot be marked optional. The parameter will always exist when determining the type:

interface A {
  [index?: string]: boolean;
}

Fix: Remove the question mark token.

To fix the error, just remove the ? token:

interface A {
  [index: string]: boolean;
}