What does the following code demonstrate? function merge(a: T, b: U): T & U { return { …a, …b }; }

TypeScript Associate Hard

TypeScript Associate — Hard

What does the following code demonstrate? function merge(a: T, b: U): T & U { return { …a, …b }; }

Key points

  • The function combines properties of T and U into a single type
  • It ensures type safety by creating an intersection type
  • This allows for flexible merging of different types
  • The resulting type will have all properties from both T and U

Ready to go further?

Related questions