promise/valid-params
Require the right number of arguments for Promise methods
Promise methods don't complain about extra or missing arguments. Promise.all(a, b) ignores b, and rejects unless a is iterable. promise.catch() without a handler catches nothing.
| Method | Arguments |
|---|---|
Promise.resolve, Promise.reject | 0 or 1 |
Promise.all, Promise.allSettled, Promise.any, Promise.race | 1 |
then | 1 or 2 |
catch, finally | 1 |
A then, catch or finally method on something that clearly isn't a promise, such as an object literal or new Parser(), isn't reported.
Configure#
Off by default. To turn it on:
bunfig.toml
[lint.rules]
"promise/valid-params" = "error" # or "warn"Examples#
example.js1 problem
const results = Promise.all(loadUser(), loadOrders())Promise.all() requires 1 argument, but received 2.;example.js2 problems
save(draft).then()Promise.catch() requires 1 argument, but received 0.Promise.then() requires 1 or 2 arguments, but received 0..catch()Promise.catch() requires 1 argument, but received 0.;example.jsNo problems
const results = Promise.all([loadUser(), loadOrders()]);
save(draft).then(notify, retry).catch(showError);
const parser = new Parser();
parser.then();