-
-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix deep-assign utility Fixes regression in #123
- Loading branch information
Showing
3 changed files
with
8 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,16 @@ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */ | ||
export const deepAssign = <O>(target: O, source: any): O => { | ||
const result: Record<any, unknown> = {}; | ||
|
||
for (const [key, value] of Object.entries(target)) { | ||
export const deepAssign = (target: any, source: any): any => { | ||
for (const [key, value] of Object.entries(source)) { | ||
|
||
// Use the default value if there's no value specified | ||
result[key] = source[key] === undefined ? target[key as keyof O] : | ||
target[key] = value === undefined ? target[key as keyof O] : | ||
|
||
// Check if it's a nested object and merge if required | ||
(typeof value === 'object' && value !== null && !Array.isArray(value)) ? | ||
deepAssign(value as O, source[key] as Partial<O>) : source[key]; | ||
deepAssign(target[key], source[key] as Partial<O>) : | ||
source[key]; | ||
} | ||
|
||
return result as O; | ||
return target; | ||
}; |