Created
November 6, 2021 07:44
-
-
Save ali-master/c4a72c2d4925bb53bbac88cc842b69ae to your computer and use it in GitHub Desktop.
RequireOnlyOne & PartialOnlyOne in 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
type RequireOnlyOne<T, Keys extends keyof T = keyof T> = Pick<T, Exclude<keyof T, Keys>> & { | |
[K in Keys]-?: Required<Pick<T, K>>; | |
}[Keys]; | |
type PartialOnlyOne<T, Keys extends keyof T = keyof T> = Pick<T, Exclude<keyof T, Keys>> & { | |
[K in Keys]?: Partial<Pick<T, K>>; | |
}[Keys]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment