diff --git a/src/decorated-merger.ts b/src/decorated-merger.ts index 47b7277..8730c46 100644 --- a/src/decorated-merger.ts +++ b/src/decorated-merger.ts @@ -70,12 +70,11 @@ export const merger = ( } const allProperties = getAllPropertiesToMerge(merge, options) for (const property of allProperties) { - const typeNew = typeof merge - if (typeNew === 'undefined' || typeNew === 'function') { - continue - } const oldValue = into[property.name] const newValue = merge[property.name] + if (newValue === undefined) { + continue + } if (oldValue === undefined) { into[property.name] = newValue continue diff --git a/test/merge.test.ts b/test/merge.test.ts index 03bf03c..e6ec35b 100644 --- a/test/merge.test.ts +++ b/test/merge.test.ts @@ -90,6 +90,15 @@ describe('Merging', () => { expect(newMovie.to).toBeDefined() }) + it('Undefinded in new object should not override', () => { + let movieA = { title: 'test', genre: ['Drama'] } + const movieB = { title: undefined, genre: undefined } + const newMovie = merger(movieB, movieA) + + expect(newMovie.title).toEqual('test') + expect(newMovie.genre[0]).toEqual('Drama') + }) + it('Two simple class with exsiting array should merge', () => { const car = getTestCar() const carNew = getTestCar()