This repository has been archived by the owner on Mar 25, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 887
Rule suggestion: prefer object spread to Object.assign #2618
Milestone
Comments
@danvk You can already do that with the On second thought using Object.assign(obj1, obj2); |
Yeah, this has slightly more complex semantics than "ban" would allow. If
it's specifically mentioned in the AirBnb guide, I think it warrants a rule.
…On Thu, Apr 20, 2017 at 5:36 PM Klaus Meinhardt ***@***.***> wrote:
@danvk <https://github.com/danvk> You can already do that with the ban
rule and add an appropriate message. This doesn't have automatic fixing
though.
On second thought using ban would also disallow cases where you really
want to assign properties of one object to another without creating a new
one.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#2618 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAF__VR083RY0zlElN-Wpeo4qACh3J6Cks5rx8_kgaJpZM4NDmPs>
.
|
For what it's worth, an Object Spread does not appear to be the exact equivalent of Object.assign:
In this case,
Here, value is an instance of Object. This auto-fix just broke a bunch of my unit-tests... no biggie... just turned it off, but I figured I'd mention it in case someone thought the two were exactly equivalent. |
Is the issue just with new? Or with any object with a prototype other than
Object.prototype?
…On Wed, May 24, 2017 at 7:26 PM Adi Dahiya ***@***.***> wrote:
that's a good point @etsuo <https://github.com/etsuo>... the rule should
probably make an exception for when the first argument to Object.assign is
a new SomeConstructor(...) expression because spread is not functionally
equivalent
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#2618 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAF__QwX3DonKQotOqfSKKEh3kxZHPEfks5r9Ly9gaJpZM4NDmPs>
.
|
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Now that TS supports the object-spread operator, the idea would be to suggest replacing code like this:
with
See https://github.com/airbnb/javascript#objects--rest-spread
The text was updated successfully, but these errors were encountered: