Skip to content

Instantly share code, notes, and snippets.

@sky0014
Created February 21, 2022 08:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sky0014/f62a41f1facd84e31ac4da1867fa2bcf to your computer and use it in GitHub Desktop.
Save sky0014/f62a41f1facd84e31ac4da1867fa2bcf to your computer and use it in GitHub Desktop.
Magical UnionToIntersection of typescript
// from https://stackoverflow.com/questions/50374908/transform-union-type-to-intersection-type by jcalz
type UnionToIntersection<U> =
(U extends any ? (k: U)=>void : never) extends ((k: infer I)=>void) ? I : never
@sky0014
Copy link
Author

sky0014 commented Feb 21, 2022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment