fix(merge, mergeWith): Handle top-level type mismatch consistently#1530
Open
fix(merge, mergeWith): Handle top-level type mismatch consistently#1530
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes inconsistent behavior in merge and mergeWith functions when handling type mismatches between target and source arguments. Previously, top-level type mismatches (e.g., array target with object source) behaved differently than nested property type mismatches. The fix ensures that in both cases, the source type takes precedence.
Key changes:
- Added top-level type checking in both
mergeandmergeWithto detect array/object mismatches before iteration - When types mismatch, creates a fresh target of the source's type and recursively merges
- Added test cases demonstrating the consistent behavior between top-level and nested type mismatches
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/object/merge.ts | Added top-level type mismatch detection (lines 48-56) that creates fresh target when types don't match |
| src/object/mergeWith.ts | Added identical top-level type mismatch detection (lines 57-65) consistent with merge.ts |
| src/object/merge.spec.ts | Added test verifying top-level type mismatch behavior matches nested behavior |
| src/object/mergeWith.spec.ts | Added test verifying top-level type mismatch behavior matches nested behavior for mergeWith |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
91ba7a6 to
277255b
Compare
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
Fixes #1394
mergeandmergeWithnow handle top-level type mismatches consistently with nested property behavior.Before
After
Changes
PR fix(merge): Handle edge-case for
merge#556