Skip to content

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

Merged
merged 3 commits into from
Jul 31, 2025
Merged

chore: avoid Object.assign #1166

merged 3 commits into from
Jul 31, 2025

Conversation

Uzlopak
Copy link
Contributor

@Uzlopak Uzlopak commented Jul 30, 2025

Resolves #ISSUE_NUMBER


Before the change?

After the change?

Pull request checklist

  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been reviewed and added / updated if needed (for bug fixes / features)

Does this introduce a breaking change?

Please see our docs on breaking changes to help!

  • Yes
  • No

Copy link
Contributor

👋 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 Status: Up for grabs. You & others like you are the reason all of this works! So thank you & happy coding! 🚀

G-Rath
G-Rath previously requested changes Jul 30, 2025
Copy link
Member

@G-Rath G-Rath left a 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)

@github-project-automation github-project-automation bot moved this from 🆕 Triage to 🏗 In progress in 🧰 Octokit Active Jul 30, 2025
@Uzlopak
Copy link
Contributor Author

Uzlopak commented Jul 30, 2025

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.

@G-Rath
Copy link
Member

G-Rath commented Jul 30, 2025

  • you're adding a new property to the types
  • you're making the properties not enumerable (which is technically a breaking change, but it's probably fine)
  • performance improvements are not without actual numbers to back them up

I'm not saying this change shouldn't be landed, but there is a reason we have a PR template

@Uzlopak
Copy link
Contributor Author

Uzlopak commented Jul 30, 2025

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.

@Uzlopak
Copy link
Contributor Author

Uzlopak commented Jul 30, 2025

@G-Rath

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.

@wolfy1339
Copy link
Member

This would be a bug fix for the types.

Is it really faster to not use Object.assign ?
At what point does it really matter?

@Uzlopak
Copy link
Contributor Author

Uzlopak commented Jul 31, 2025

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.

wolfy1339
wolfy1339 previously approved these changes Jul 31, 2025
Copy link
Member

@wolfy1339 wolfy1339 left a 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

@wolfy1339 wolfy1339 dismissed G-Rath’s stale review July 31, 2025 18:38

Concerns addressed

@wolfy1339 wolfy1339 merged commit 4c36fce into octokit:main Jul 31, 2025
11 checks passed
@github-project-automation github-project-automation bot moved this from 🏗 In progress to ✅ Done in 🧰 Octokit Active Jul 31, 2025
Copy link
Contributor

🎉 This PR is included in version 14.1.3 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

3 participants