Skip to content

Latest commit

 

History

History
50 lines (35 loc) · 1.2 KB

no-single-promise-in-promise-methods.md

File metadata and controls

50 lines (35 loc) · 1.2 KB

Disallow passing single-element arrays to Promise methods

💼 This rule is enabled in the ✅ recommended config.

🔧💡 This rule is automatically fixable by the --fix CLI option and manually fixable by editor suggestions.

Passing a single-element array to Promise.all(), Promise.any(), or Promise.race() is likely a mistake.

Fail

const foo = await Promise.all([promise]);
const foo = await Promise.any([promise]);
const foo = await Promise.race([promise]);
const promise = Promise.all([nonPromise]);

Pass

const foo = await promise;
const promise = Promise.resolve(nonPromise);
const foo = await Promise.all(promises);
const foo = await Promise.any([promise, anotherPromise]);
const [{value: foo, reason: error}] = await Promise.allSettled([promise]);