What does the following type compute and what technique does it use? type UnionToIntersection = (U extends any ? (x: U) => void : never) extends (x: infer I) => void ? I : never;

TypeScript Professional Hard

TypeScript Professional — Hard

What does the following type compute and what technique does it use? type UnionToIntersection = (U extends any ? (x: U) => void : never) extends (x: infer I) => void ? I : never;

Key points

  • Contravariance of function parameters is utilized
  • Union members become function parameter types
  • All union members must be satisfied simultaneously
  • Inference is used to determine the resulting intersection type

Ready to go further?

Related questions