fix(uniqWith): match lodash comparator argument order in compat#1729
Merged
Conversation
The compat `uniqWith` passed the comparator straight to the non-compat implementation, which invokes it as `(kept, candidate)`. lodash documents and invokes the comparator as `(candidate, kept)`, so asymmetric comparators produced different results after migrating to es-toolkit/compat. Wrap the comparator to swap the arguments so the call order matches lodash.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes es-toolkit/compat’s uniqWith to match lodash’s documented comparator argument order, ensuring asymmetric comparators behave identically when migrating from lodash.
Changes:
- Update compat
uniqWithto swap comparator arguments so calls become(candidate, kept)(lodash-compatible). - Add tests to assert comparator invocation order and verify behavior with an asymmetric “subset” comparator.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/compat/array/uniqWith.ts | Wraps the comparator to forward toolkit’s (kept, candidate) invocation as lodash’s (candidate, kept). |
| src/compat/array/uniqWith.spec.ts | Adds tests covering comparator argument order and an asymmetric comparator behavioral case. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
raon0211
approved these changes
May 22, 2026
Collaborator
raon0211
left a comment
There was a problem hiding this comment.
Thanks for catching ths!
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'suniqWithinvoked the comparator with reversed argument order compared to lodash. lodash calls the comparator as(candidate, kept)(documented(arrVal, othVal)), but compat passed the comparator straight to the non-compat implementation, which calls it as(kept, candidate). Any asymmetric comparator silently produced different results after migrating from lodash.Changes
uniqWithso the toolkit's(kept, candidate)call is forwarded ascomparator(candidate, kept), matching lodash.(candidate, kept)order, plus a behavioral test for an asymmetric (subset) comparator.The non-compat
uniqWithkeeps its own documented(item1, item2)semantics and is unchanged.Test plan
yarn vitest run src/compat/array/uniqWith.spec.ts— 19 passed (new tests fail before the fix)yarn vitest run src/compat/array/— 1000 passeduniqWithunaffected; typecheck + lint cleanCloses #1728