fix(compat/mergeWith): treat a trailing non-function argument as a source - #2070
Open
ilievskizoran wants to merge 3 commits into
Open
fix(compat/mergeWith): treat a trailing non-function argument as a source#2070ilievskizoran wants to merge 3 commits into
ilievskizoran wants to merge 3 commits into
Conversation
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The updated documentation code snippets use invalid customizer? syntax in a function call and should be corrected.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR fixes es-toolkit/compat’s mergeWith to match Lodash behavior by only treating the last argument as a customizer when it’s a function, otherwise merging it as an additional source.
Changes:
- Update
compat/mergeWithruntime behavior to detect whether a trailing customizer is callable and default tonoopwhen it isn’t. - Add test coverage ensuring trailing non-function arguments are merged as sources and trailing functions are still treated as customizers.
- Update compat docs (all languages) to describe the “customizer is optional / only if function” behavior (but the top snippet currently uses invalid
customizer?call syntax).
File summaries
| File | Description |
|---|---|
| src/compat/object/mergeWith.ts | Detects whether the last argument is a function; merges all args as sources when no customizer is provided and uses noop as the default customizer. |
| src/compat/object/mergeWith.spec.ts | Adds regression tests for trailing non-function vs function last-argument handling, plus default deep-merge behavior without a customizer. |
| docs/compat/reference/object/mergeWith.md | Documents optional customizer behavior; top snippet needs valid TypeScript call syntax. |
| docs/ko/compat/reference/object/mergeWith.md | Same documentation update as English; top snippet needs valid TypeScript call syntax. |
| docs/ja/compat/reference/object/mergeWith.md | Same documentation update as English; top snippet needs valid TypeScript call syntax. |
| docs/zh_hans/compat/reference/object/mergeWith.md | Same documentation update as English; top snippet needs valid TypeScript call syntax. |
Review details
- Files reviewed: 6/6 changed files
- Comments generated: 4
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
es-toolkit/compat/mergeWithdiffers in behaviour tolodashwith regards to the customizer.lodashchecks the last argument is a function, and treats it as another source if it is not, performing a standardmerge.es-toolkitdoes not have the function check, and does two things based on arguments:Changes
typeof functioncheck for the last argument.noop.compat/mergeessentially already implements this behaviour:Benchmark results
main
PR