Created
February 21, 2022 08:53
-
-
Save sky0014/f62a41f1facd84e31ac4da1867fa2bcf to your computer and use it in GitHub Desktop.
Magical UnionToIntersection of typescript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How it works:
microsoft/TypeScript#29594 (comment)