-
Notifications
You must be signed in to change notification settings - Fork 81
chore: avoid Object.assign #1166
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
👋 Hi! Thank you for this contribution! Just to let you know, our GitHub SDK team does a round of issue and PR reviews twice a week, every Monday and Friday! We have a process in place for prioritizing and responding to your input. Because you are a part of this community please feel free to comment, add to, or pick up any issues/PRs that are labeled with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this change does more than just remove the Object.assign
- could you retitle your PR to be either a fix
or feat
, and provide more explanation on why you think this change is needed (even better if you could add a test related to it)
Why is it doing more than removing Object.assign? It is the same behaviour than before. event and status are not non-wrtieable or non-configurable propertie on a generic Error. And Object.assign makes them also enumerable. Obviously Object.assign is slightls slower than just assigning the properties. |
I'm not saying this change shouldn't be landed, but there is a reason we have a PR template |
Ok, I have now to check if assigning with Object.assign is different then directly assigning the properties. Thank you for this precious hint. No sarcasm or so. I am quiet impressed regarding this aspect I did not see. |
I checked it, and directly assigning makes them also enumerable. So there is no breaking change. const bla = { a: 1}
Object.assign(bla, { b: 2 });
bla.c = 3;
Object.defineProperty(bla, 'd', {
value: 4,
enumerable: false,
});
console.log(bla.propertyIsEnumerable('a')); // true
console.log(bla.propertyIsEnumerable('b')); // true
console.log(bla.propertyIsEnumerable('c')); // true
console.log(bla.propertyIsEnumerable('d')); // false And yes, mutating is always faster. Object. assign is actually mutating the Object, thus if you would use a Proxy you could see that the setters are triggered on the Object. The type change actually just demonstrates, that the properties were missing on the type. The Object.assign actually hid the the fact that those propertes were not documented. |
This would be a bug fix for the types. Is it really faster to not use Object.assign ? |
You are right. We have other bottlenecks. Actually verification could/should be improved. When I started working on #1167 i opened my local project and saw these changes, and i thought, that I should propose it. Object.assign swallowed the issue of lack of typings. So this was the reason why i wrote that it avoids Object.assign. The slightly faster remark in my first answer was just a clarifying that it has also some kind of perf effect. But it was not my main target. I can add back the Object.assign, if you like. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe that the fact that this fixes a type issue and fixes the fact that the properties were hidden from typescript and thus the type issue not detected, make this PR just fine
🎉 This PR is included in version 14.1.3 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Resolves #ISSUE_NUMBER
Before the change?
After the change?
Pull request checklist
Does this introduce a breaking change?
Please see our docs on breaking changes to help!