💼 This rule is enabled in the ✅ recommended
config.
If an object is defined as "thenable", once it's accidentally used in an await expression, it may cause problems:
const foo = {
unicorn: 1,
then() {},
};
const {unicorn} = await foo;
console.log('after'); //<- This will never execute
const foo = {
unicorn: 1,
then() {
throw new Error('You shouldn’t have called me')
},
};
const {unicorn} = await foo;
// Error: You shouldn’t have called me
If a module has an export named then
, dynamic import()
may not work as expected:
// foo.js
export function then () {
throw new Error('You shouldn’t have called me')
}
// bar.js
const foo = await import('./foo.js');
// Error: You shouldn’t have called me
export {then};
const foo = {
then() {}
};
const foo = {
get then() {}
};
foo.then = function () {}
class Foo {
then() {}
}
class Foo {
static then() {}
}
export {then as success};
const foo = {
success() {}
};
class Foo {
success() {}
}
const foo = bar.then;