the tswhy logo: a question mark in a box

tswhy‽

A community effort to enrich TypeScript diagnostics.

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() {},
    };
  }
}