This rule raises an issue when an object, class, or module defines a property or method named then.
JavaScript treats objects with a then property as "thenable" - similar to Promises. This can cause unexpected behavior when these
objects are used with await expressions or dynamic imports.
When JavaScript encounters an object with a then property in an await expression, it assumes the object is Promise-like
and tries to resolve it. This can lead to:
then method doesn’t behave like a Promise then method throws an exception The same issue occurs with dynamic imports. If a module exports a then function, the import statement will treat the entire module as
thenable, potentially calling the then function instead of returning the module object.
This behavior stems from JavaScript’s Promise resolution algorithm, which checks for a then property to determine if an object should
be treated as a Promise.
This issue can cause applications to hang indefinitely, throw unexpected errors, or fail silently. In production environments, this could lead to
unresponsive user interfaces, incomplete data processing, or application crashes. The debugging experience is particularly poor because the connection
between the then property and the problematic behavior is not immediately obvious.
Rename the then property to a more descriptive name that reflects its actual purpose.
const userAction = {
userId: 123,
then() { // Noncompliant
console.log('Action completed');
}
};
const userAction = {
userId: 123,
complete() {
console.log('Action completed');
}
};