the tswhy logo: a question mark in a box

tswhy‽

A community effort to enrich TypeScript diagnostics.

Editing TS1058:

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.

TS1058

The return type of an async function must either be a valid promise or must not contain a callable 'then' member.

Async functions cannot return objects with a callable then property as Javascript aggressively flattens promises. Therefore the following is an error:

class A {
  async test() {
    return {
      then() {},
    };
  }
}

See also

Fix: Rename the method/property.

The best fix for this error is to rename the then method on the object you are returning to something else. chain or map might be appropriate:

class A {
  async test() {
    return {
      chain() {},
    };
  }
}