Skip to content

no-async-constructor

Disallows async work inside constructors.

Constructors return before async work finishes. This rule reports patterns that leave an instance half-initialized or drop promise errors on the floor.

It reports:

  • await inside a constructor
  • promise chains like .then(), .catch(), and .finally()
  • async IIFEs called from the constructor
  • bare calls to async methods on this, such as this.load()
  • promises from async methods stored in a local variable and never used

It does not report this.loadPromise = this.load();, because the promise stays on the instance and can be consumed by callers.

Incorrect
class Database {
constructor() {
this.connect().then(() => logReady());
}
async connect() {}
}
Correct
class Database {
private constructor() {}
static async create() {
const database = new Database();
await database.connect();
return database;
}
async connect() {}
}
  • use static async create() when construction depends on async setup
  • expose an init() method and make callers await it before use
  • if you must start work in the constructor, store the promise on this so the lifecycle is visible