prefer-rest-params
Require rest parameters instead of arguments
warn by default
arguments looks like an array but isn't one. It has no map, slice or join. And function log(level) doesn't show that the function takes more than one argument. A rest parameter such as ...parts is a real array, and you can see it in the signature.
Reading a named property, such as arguments.length, isn't reported.
This rule is on by default in TypeScript files.
Configure#
On by default as a warning. To turn it off:
bunfig.toml
[lint.rules]
"prefer-rest-params" = "off" # or "error"Examples#
example.js1 problem
function log(level) {
const parts = Array.prototype.slice.call(argumentsUse the rest parameters instead of arguments., 1);
console.log(level, parts.join(" "));
}example.jsNo problems
function log(level, ...parts) {
console.log(level, parts.join(" "));
}
function hasOptions() {
return arguments.length > 1;
}