Linter · Rules
oxc/no-rest-spread-properties
Disallow ... in object literals and object destructuring
Engines older than ES2018 can't parse { ...user } or const { id, ...rest } = user, so a file that uses them fails to load there. If a compiler lowers them for a target like that, it adds helper code to the output.
Only objects are checked. ... is allowed in arrays, call arguments, rest parameters such as (...args), and JSX attributes.
Configure
Off by default. To turn it on:
bunfig.toml
[lint.rules]
"oxc/no-rest-spread-properties" = "error" # or "warn"
Every option, set to its default:
bunfig.toml
[lint.rules]
"oxc/no-rest-spread-properties" = ["error", {
objectSpreadMessage = "", # string
objectRestMessage = "", # string
}]
Examples
Reported:
const updated = { ...user, name: "Ada" };
const { password, ...profile } = user;
Not reported:
const updated = Object.assign({}, user, { name: "Ada" });
const profile = { id: user.id, name: user.name };
const all = [...admins, ...members];
function log(...messages) {
console.log(...messages);
}
const row = <Row {...props} />;
Options
| Option | Default | What it does |
|---|---|---|
objectSpreadMessage | "" | Text to add to the message for a spread, such as { ...user }. |
objectRestMessage | "" | Text to add to the message for a rest property, such as { id, ...rest } = user. |
const updated = { ...user, name: "Ada" };
When not to use it
Every current browser and runtime supports both. Only use this rule if your code has to run on older ones.