Skip to content

Commit

Permalink
fix: preserve null prototype in assign result
Browse files Browse the repository at this point in the history
  • Loading branch information
aleclarson committed Jun 25, 2024
1 parent dabbaaa commit 9dc1b70
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/object/assign.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ export const assign = <X extends Record<string | symbol | number, any>>(
override: X
): X => {
if (!initial || !override) return initial ?? override ?? {}
const merged = { ...initial }
const proto = Object.getPrototypeOf(initial)
const merged = proto
? { ...initial }
: Object.assign(Object.create(proto), initial)
for (const key in override) {
if (Object.prototype.hasOwnProperty.call(override, key)) {
merged[key] = isPlainObject(initial[key])
Expand Down

0 comments on commit 9dc1b70

Please sign in to comment.