the tswhy logo: a question mark in a box

tswhy‽

A community effort to enrich TypeScript diagnostics.

Editing TS1005:

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.

TS1005

'{0}' expected.

Occurs when various syntax characters are making the code invalid.

Fix: '=' expected with type aliases

Unlike interfaces, type aliases must have a left hand side and right hand side of a statement, so code like this is invalid syntax:

type Person {
  age: number;
  name: string;
}

Instead it should look like this:

type Person = {
  age: number;
  name: string;
};

Fix: ';' expected with arrow functions

Code like this is trying to implicitly return an object with the map function, but is actually invalid syntax:

const items = [["a", 1], ["b", 2]];
const mapped = items.map(([key, value]) => { [key]: value });

Instead, use parenthesis (()) around the return value:

const items = [["a", 1], ["b", 2]];
const mapped = items.map(([key, value]) => ({ [key]: value }));