From 9dc1b703c483b1216e43c954d8a6b52644993153 Mon Sep 17 00:00:00 2001 From: Alec Larson <1925840+aleclarson@users.noreply.github.com> Date: Tue, 25 Jun 2024 13:00:33 -0400 Subject: [PATCH] fix: preserve null prototype in assign result --- src/object/assign.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/object/assign.ts b/src/object/assign.ts index ad79bbf2..95218bae 100644 --- a/src/object/assign.ts +++ b/src/object/assign.ts @@ -10,7 +10,10 @@ export const assign = >( 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])