What does the following produce? type UnionToIntersection = (U extends any ? (x: U) => void : never) extends (x: infer I) => void ? I : never;

TypeScript Associate Hard

TypeScript Associate — Hard

What does the following produce? type UnionToIntersection = (U extends any ? (x: U) => void : never) extends (x: infer I) => void ? I : never;

Key points

  • Conditional types are used to create a type that transforms a union to an intersection
  • The infer keyword is crucial in capturing the resulting type from a conditional type check
  • Function parameter contravariance is utilized to achieve the desired conversion

Ready to go further?

Related questions