-
Notifications
You must be signed in to change notification settings - Fork 341
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
fix(groupBy): preserve Object prototype method #902
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Hello, thanks for helping us! The design principle for es-toolkit is to support everyday usecase, but skip edge cases. (You can refer to our contributing docs). Is there an actual usecase for the behavior you described? I'm asking because I thought we don't usually access prototype methods when using groupBy. |
@raon0211 As you mentioned, there are no direct uses of prototype methods in my code. However, I encountered an issue in a situation beyond my direct control:
While the build output works correctly in production, errors occur in the development environment. This is clearly a situation that developers cannot directly control, and I believe it can be quite tricky to debug. From my perspective, it feels unnatural for an object to lack its prototype methods when its type is clearly an object - similar to how it would be strange for an array to lack its prototype methods. However, I understand that this case could be considered an edge case according to es-toolkit's design principles, and I respect your perspective on this matter. Thank you for your feedback. |
Hi, thanks for your help! I see what you pointed out. While reviewing other functions, I noticed that many of them, like However, I wasn’t sure if this is something we need to enforce with test cases, so I removed that part. |
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.
Thanks!
Thank you for understanding.
I agree with this point. The commit caused existing tests to fail. Another person has submitted a #906 to address this issue. |
What this PR solves
groupBy
function to properly preserve Object prototype (liketoString
,valueOf
).Motivation
While implementing "fix(groupBy): Support keys like toString or valueOf in groupBy", we noticed that prototype methods were removed entirely. This is likely unintended behavior unless the user specifically uses these method names as keys.
For example, even when not using 'toString' as a grouping key, attempting to convert the result object to a string would fail: