π Disallow invalid implementations of well-known symbol methods.
πΌ This rule is enabled in the following configs: β
recommended, βοΈ unopinionated.
π§π‘ This rule is automatically fixable by the --fix CLI option and manually fixable by editor suggestions.
Some well-known symbol methods must return protocol objects directly. Marking those methods as async or returning a Promise changes the value seen by the protocol, which does not unwrap it.
Symbol.dispose is also synchronous. A Promise returned from it is ignored by using and is not awaited. A generator disposer is also invalid because calling it does not run the body. Use a normal method for synchronous disposal or Symbol.asyncDispose for asynchronous disposal.
// β
class Resource {
async [Symbol.dispose]() {}
}
// β
class Resource {
async [Symbol.asyncDispose]() {}
}// β
const iterable = {
async *[Symbol.iterator]() {
yield value;
},
};
// β
const iterable = {
async *[Symbol.asyncIterator]() {
yield value;
},
};// β
const asyncIterable = {
async [Symbol.asyncIterator]() {
return iterator;
},
};
// β
const asyncIterable = {
async *[Symbol.asyncIterator]() {
yield value;
},
};