Skip to content

Instantly share code, notes, and snippets.

@manavm1990
Created August 22, 2023 15:26
Show Gist options
  • Save manavm1990/fd2ab530cf08cdaac2f3d29423b5e647 to your computer and use it in GitHub Desktop.
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......
// 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