An option that technically fulfills the linter rules would be to declare rest
upfront, destructure the a
property into rest
, and then use rest syntax to put the rest of the object into the rest
variable name:
const initObject = {
a: 0,
b: 0,
c: 0
};
let rest;
({ a: rest, ...rest } = initObject);
console.log(rest);
Unfortunately, if you want to avoid var
, you can't do it in just a single line like
let { a: rest, ...rest } = initObject
because when the left-hand side of the {
declares a variable, each new variable name on the right side is initialized separately - that is, to the interpreter it looks a bit like
let rest = initObject.a;
let rest = <everything else in initObject>
But duplicate let
identifiers for the same variable name is not permitted. You could do it in one line with var
, for which duplicate identifiers are permitted:
const initObject = {
a: 0,
b: 0,
c: 0
};
var { a: rest, ...rest } = initObject;
console.log(rest);
But this is all a little bit odd. I'd prefer to configure/ignore the linter, or use something other than destructuring, as other answers have suggested.