What does `type MergeIntersection = T extends infer O ? { [K in keyof O]: O[K] } : never` accomplish?

TypeScript Professional Hard

TypeScript Professional — Hard

What does `type MergeIntersection = T extends infer O ? { [K in keyof O]: O[K] } : never` accomplish?

Key points

  • This code snippet leverages conditional types to merge intersected object types.
  • The `infer` keyword helps capture the type of `O` during the conditional check.
  • The resulting type `MergeIntersection` contains all properties from the intersected objects in a flat structure.

Ready to go further?

Related questions