Proposal: minus operator for the spread operator

Felipe Nascimento de Moura felipenmoura at gmail.com
Tue May 12 13:43:33 UTC 2020


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
<https://developers.google.com/experts/people/felipe-moura>, Founder of
BrazilJS <https://braziljs.org/>, Nasc <http://nasc.io/> and On2
<https://on2.dev/>.

Website:  http://felipenmoura.com / http://nasc.io/
Twitter:    @felipenmoura <http://twitter.com/felipenmoura>
Facebook: http://fb.com/felipenmoura
LinkedIn: http://goo.gl/qGmq
---------------------------------
* Changing  the  world*  is the least I expect from  myself!


On Sun, May 3, 2020 at 6:57 AM devlato <ecma6 at devlato.com> wrote:

> Hey folks,
>
> I've figured out a potential improvement for the object spread syntax and
> want to share my thoughts.
> I've drafted my thoughts into a proposal available here:
> https://github.com/devlato/proposal-plus-minus-spread
> <https://github.com/devlato/proposal-plus-minus-spread/blob/master/README.md>
>
> Long story short, I want to propose a new **minus operator**, that would
> allow specify keys to remove the values from a result of object spread. It
> would look like this:
>
>
> const result = {
>   ...objA,
>   ...objB,
>   -keyToRemove,};
> // Or like this – the same result!const result = {
>   ...objA,
>   -keyToRemove,
>   ...objB,};
> // And this!const result = {
>   -keyToRemove,
>   ...objA,
>   ...objB,};
>
>
> What do you folks think?
>
> Warmest regards,
> Denis
>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20200512/afc5be06/attachment.html>


More information about the es-discuss mailing list