Proposal: minus operator for the spread operator

# devlato (4 years ago)

An HTML attachment was scrubbed... URL: esdiscuss/attachments/20200503/f1c9c229/attachment

# Felipe Nascimento de Moura (4 years ago)

hm, personally, I find it useful when extracting properties from objects!

I have myself been in situations where I had to deal with "all other properties except...". An alternative would be simply extract it normally, but ignore it (which triggers complaints from linters).

Perhaps ! could be a better option (makes me think of .gitignore and other list remove syntaxes.

const { propA, propB, !keyToRemove, ...other } = objectA;

Note that, if you are not getting the "rest" of the properties in an ...other constant, it would not be as useful. In this case, keyToRemove would NOT be declared, and other would have all properties except propA, propB and keyToRemove.

Other thing I find rather annoying is the way we have to deal with some APIs when we are trying to "clean" their returned objects. Like so:

function cleanData (data) { const { propA, propB, propC, propD, propE } = data; return { propA, propB, propC, propD, propE }; }

Perhaps something like this could become an option?!

function cleanData (data) { const { propA, propB, propC, propD, propE } as newObj = data; return newObj; }

[ ]s


Felipe N. Moura Web Developer, Google Developer Expert, Founder of

BrazilJS, Nasc and On2

Website: / Twitter: @felipenmoura

Facebook: LinkedIn:

  • Changing the world* is the least I expect from myself!