Last active
December 3, 2019 20:44
-
-
Save forivall/5ffe686c102614312c03394e3c549738 to your computer and use it in GitHub Desktop.
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
export type Deintersect<T> = Compute< | |
OptionalizeUndefined< | |
{ | |
[K in keyof UnionToIntersection<T>]: T extends { [_ in K]: any } | |
? T[K] | |
: undefined; | |
} | |
> | |
>; | |
type Compute<A> = { | |
[K in keyof A]: A[K]; | |
} & {}; | |
type OptionalizeUndefined<T> = { | |
[K in UndefKeys<T>]?: NonUndef<T[K]>; | |
} & | |
{ [K in Exclude<keyof T, UndefKeys<T>>]: T[K] }; | |
type NonUndef<T> = T extends undefined ? never : T; | |
type UndefKeys<T> = Exclude< | |
{ | |
[K in keyof T]: T extends Record<K, NonUndef<T[K]>> ? never : K; | |
}[keyof T], | |
undefined | |
>; | |
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