Skip to content

Latest commit

 

History

History
104 lines (79 loc) · 1.35 KB

no-thenable.md

File metadata and controls

104 lines (79 loc) · 1.35 KB

Disallow then property

💼 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

Fail

export {then};
const foo = {
	then() {}
};
const foo = {
	get then() {}
};
foo.then = function () {}
class Foo {
	then() {}
}
class Foo {
	static then() {}
}

Pass

export {then as success};
const foo = {
	success() {}
};
class Foo {
	success() {}
}
const foo = bar.then;