HomeAmir Hossein Shekari (Vanenshi)

Union to Intersection

Convert union to intersection types

  • #typescript
export type UnionToIntersection<T> = (T extends any ? (k: T) => void : never) extends (
  // without this extends you get `T`
  k: infer I,
) => void
  ? I
  : never;

Tweet this snippet

Edit on github

Amir Hossein Shekari

Passionate UI engineer looking to bridge the gap between design and code

All rights reserved © Amir Hossein Shekari 2024