Skip to content

Commit

Permalink
fix(utilities): fixed overwrite ignore logic
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewcourtice committed Sep 6, 2021
1 parent 633076b commit c1e4b49
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
7 changes: 5 additions & 2 deletions packages/utilities/src/object/overwrite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ export default function overwrite<TTarget extends object, TSource extends object
}

for (const prop in target) {
if (!ignorePattern || !ignorePattern.test(prop)) {
delete target[prop];
if (ignorePattern && ignorePattern.test(prop)) {
delete (source as Record<string, unknown>)[prop];
continue;
}

delete target[prop];
}

return Object.assign(target, source);
Expand Down
1 change: 1 addition & 0 deletions packages/utilities/test/overwrite.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ describe('Utilities', () => {
a: 'hello',
b: 5,
c: [1, 2],
d: 35,
}, /^d/);

expect(typeof source.a).toBe('string');
Expand Down

0 comments on commit c1e4b49

Please sign in to comment.