From 8057704dfa468feb2e5d7b559a85311d25e41253 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=8C=E8=B4=A7=E6=9C=BA=E5=99=A8=E4=BA=BA?= Date: Sat, 18 May 2024 00:56:35 +0800 Subject: [PATCH] fix: proxyObject ignore empty type --- src/proxyObject.ts | 2 +- tests/proxyObject.test.ts | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/proxyObject.ts b/src/proxyObject.ts index d27e0ac7..5c8d1b49 100644 --- a/src/proxyObject.ts +++ b/src/proxyObject.ts @@ -5,7 +5,7 @@ export default function proxyObject< Obj extends object, ExtendObj extends object >(obj: Obj, extendProps: ExtendObj): Obj & ExtendObj { - if (typeof Proxy !== 'undefined') { + if (typeof Proxy !== 'undefined' && obj) { return new Proxy(obj, { get(target, prop) { if (extendProps[prop]) { diff --git a/tests/proxyObject.test.ts b/tests/proxyObject.test.ts index 88622877..6292ef0d 100644 --- a/tests/proxyObject.test.ts +++ b/tests/proxyObject.test.ts @@ -12,4 +12,12 @@ describe('proxyObject', () => { expect(proxyA.bamboo).toBe('little'); }); + + it('null', () => { + const proxyA = proxyObject(null, { + bamboo: 'little', + }); + + expect(proxyA).toBe(null); + }); });