Skip to content

fix[merge]: keep the same type when merging an object with itself - #2144

Closed
rjsgud49 wants to merge 2 commits into
toss:mainfrom
rjsgud49:fix/merge-same-type
Closed

rjsgud49 wants to merge 2 commits into
toss:mainfrom
rjsgud49:fix/merge-same-type

Conversation

@rjsgud49

Copy link
Copy Markdown

Summary

Fixes #2141.

merge(value, value) satisfies typeof value started failing in 1.52 when the type contains string & {}, or a union of array shapes such as string[] | string[][] and string | number | T[] | T[][]. toMerged still type-checks, because its return type is T & S.

string & {} counts as an object type, so Merge walked the members of String (length, toString, and the rest). Unions with more than one array shape were merged member by member, which produced a mixed array like (string | string[])[] that is not assignable back to the original type.

Changes

Equality was only checked for pure array types, so a union such as
string | number | T[] | T[][] was still widened. Return the input type
whenever both sides are the same type.

Co-authored-by: park gunhyung <rjsgud49@users.noreply.github.com>
@vercel

vercel Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
es-toolkit Ready Ready Preview Oct 19, 2026 4:15am UTC

Request Review

@raon0211

Copy link
Copy Markdown
Collaborator

Thanks for working on this, @rjsgud49! #2148 was merged yesterday and fixes #2141, so this is already solved on main. It covers the same cases (string & {} and unions of array shapes like string[] | string[][]), and merge(value, value) now returns the input type. Thanks again for the clear write-up of the cause.

@raon0211 raon0211 closed this Oct 22, 2026

This branch was successfully deployed

1 active deployment
Preview — 31f3df4c Deployed Oct 19, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

merge() returns an incompatible type when merging two objects of the same type

2 participants