Created
August 22, 2023 15:26
-
-
Save manavm1990/fd2ab530cf08cdaac2f3d29423b5e647 to your computer and use it in GitHub Desktop.
Sometimes, merging objects with spread results in TS losing its way with inferences. It starts to complain about potential `undefined`. You COULD use type assertions......
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
// Merges additional properties into an object, ensuring type consistency. | |
export const mergeProperties = <T, U>( | |
originalObject: T, | |
additionalProps: U, | |
): T & U => { | |
return { ...originalObject, ...additionalProps }; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment