Skip to content

Type Alias: UnionToIntersection<UnionType>

UnionToIntersection<UnionType> = UnionType extends unknown ? (keyParameter) => void : never extends (keyParameter) => void ? InferredType : never

Type utility that converts a union type to an intersection type. This advanced utility uses conditional types and contravariance to transform unions.

Type Parameters

UnionType

UnionType

The union type to convert to intersection

Example

typescript
type Union = { a: string } | { b: number } | { c: boolean }

// Result: { a: string } & { b: number } & { c: boolean }
type Intersection = UnionToIntersection<Union>

// Usage example
const obj: Intersection = { a: 'hello', b: 42, c: true }

Released under the MIT License.