Skip to content

Commit

Permalink
fix(assignIn): Correct undefined assignment (#959)
Browse files Browse the repository at this point in the history
* fix(assignIn): Ensure properties with undefined values are assigned correctly

* test(assignIn): Add test case for correct assignment of undefined values
  • Loading branch information
hsskey authored Mar 9, 2025
1 parent 4a656bb commit 59d76e8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/compat/object/assignIn.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,10 @@ describe('assignIn', () => {
it(`\`assignIn\` should coerce string sources to objects`, () => {
expect(func({}, 'a')).toEqual({ 0: 'a' });
});

it(`\`assignIn\` should assign properties with undefined values correctly`, () => {
const values = [{ workId: undefined }, { exerciseId: '1' }];
const result = assignIn({}, ...values);
expect(result).toEqual({ workId: undefined, exerciseId: '1' });
});
});
3 changes: 1 addition & 2 deletions src/compat/object/assignIn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,7 @@ function assignInImpl(object: any, source: any): any {

for (let i = 0; i < keys.length; i++) {
const key = keys[i];

if (!eq(object[key], source[key])) {
if (!(key in object) || !eq(object[key], source[key])) {
object[key] = source[key];
}
}
Expand Down

0 comments on commit 59d76e8

Please sign in to comment.