HomeSegun Adebayo

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

Segun Adebayo

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

All rights reserved © Segun Adebayo 2024