Created
June 7, 2019 14:19
-
-
Save 197291/b7cf6f597e3e95927e2c51d3991c2922 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
type RequireOnlyOne<T, Keys extends keyof T = keyof T> = | |
Pick<T, Exclude<keyof T, Keys>> | |
& { [K in Keys]-?: | |
Required<Pick<T, K>> | |
& Partial<Record<Exclude<Keys, K>, undefined>> | |
}[Keys] | |
type RequireAtLeastOne<T, Keys extends keyof T = keyof T> = | |
Pick<T, Exclude<keyof T, Keys>> | |
& { | |
[K in Keys]-?: Required<Pick<T, K>> & Partial<Pick<T, Exclude<Keys, K>>> | |
}[Keys] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment