diff --git a/packages/shared/src/__tests__/index.spec.ts b/packages/shared/src/__tests__/index.spec.ts index 98156008603..ef178f3a727 100644 --- a/packages/shared/src/__tests__/index.spec.ts +++ b/packages/shared/src/__tests__/index.spec.ts @@ -698,6 +698,19 @@ describe('merge', () => { }) }) + test('empty', () => { + expect( + merge( + { + aa: undefined, + }, + { + aa: {}, + } + ) + ).toEqual({ aa: {} }) + }) + test('clone', () => { const target = { aa: { diff --git a/packages/shared/src/merge.ts b/packages/shared/src/merge.ts index c192fe31d9f..56c1661a9b4 100644 --- a/packages/shared/src/merge.ts +++ b/packages/shared/src/merge.ts @@ -1,4 +1,4 @@ -import { isValid } from './isEmpty' +import { isValid, isEmpty } from './isEmpty' import { isFn, isPlainObj } from './checkers' function defaultIsMergeableObject(value: any) { @@ -99,10 +99,9 @@ function mergeObject(target: any, source: any, options: Options) { if (propertyIsUnsafe(target, key)) { return } - if (!target[key]) { + if (isEmpty(target[key])) { destination[key] = source[key] - } - if ( + } else if ( propertyIsOnObject(target, key) && options.isMergeableObject(source[key]) ) {