the tswhy logo: a question mark in a box

tswhy‽

A community effort to enrich TypeScript diagnostics.

Editing TS1062:

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.

TS1062

Type is referenced directly or indirectly in the fulfillment callback of its own 'then' method.

When implementing a non-native promise type, if the type references itself in the `then`` method, this error will occur:

declare class BadPromise {
  then(
    onfulfilled: (value: BadPromise) => any,
    onrejected: (error: any) => any,
  ): BadPromise;
}

async function test() {
  await new BadPromise();
}

Fix: Don't use a recursive type.

To fix the error, don't use a recursive type in the definition of the promise.