Created
November 23, 2023 11:48
-
-
Save dsvgit/86bab140b1cac3b7b28e6a76be6b5eaa to your computer and use it in GitHub Desktop.
makeDefaults typescript
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
export function makeDefaults<T extends Record<string, any>, D extends Partial<T>>( | |
options: T, | |
defaults: D | |
): T & D { | |
for (const key in options) { | |
if (Object.hasOwn(options, key) && options[key] === undefined) { | |
delete options[key]; | |
} | |
} | |
return { ...defaults, ...options }; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment