typescript Feb 19, 2026
Union to Intersection
Merge a union of object types into a single composite type.
This utility turns A | B into A & B, which is useful when you collect handlers or mixins.
Type
union-to-intersection.ts
type UnionToIntersection<U> =
(U extends unknown ? (arg: U) => void : never) extends (arg: infer I) => void
? I
: never
type Handlers =
| { onClick: () => void }
| { onKey: (key: string) => void }
type Combined = UnionToIntersection<Handlers>
// Combined is { onClick: () => void } & { onKey: (key: string) => void }