Proposal: minus operator for the spread operator
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 developers.google.com/experts/people/felipe-moura, Founder of
BrazilJS braziljs.org, Nasc nasc.io and On2 on2.dev.
Website: felipenmoura.com / nasc.io Twitter: @felipenmoura twitter.com/felipenmoura
Facebook: fb.com/felipenmoura LinkedIn: goo.gl/qGmq
- Changing the world* is the least I expect from myself!
An HTML attachment was scrubbed... URL: esdiscuss/attachments/20200503/f1c9c229/attachment