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#

example.js1 problem
const updated = { ...user, name: "Ada" };
example.js1 problem
const { password, ...profile } = user;
example.jsNo problems
const updated = Object.assign({}, user, { name: "Ada" });

const profile = { id: user.id, name: user.name };
example.jsxNo problems
const all = [...admins, ...members];

function log(...messages) {
  console.log(...messages);
}

const row = <Row {...props} />;

Options#

OptionDefaultWhat 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.
example.jswith { "objectSpreadMessage": "Use Object.assign(), we ship ES2017." }1 problem
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.