Last active
September 21, 2023 15:07
-
-
Save Yimiprod/60bfc8f0e01cf7c9b96ffea9d695a092 to your computer and use it in GitHub Desktop.
typescript utils to handle keys presence in object based on https://stackoverflow.com/questions/40510611/typescript-interface-require-one-of-two-properties-to-exist
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 RequireAtLeastOne<T, Keys extends keyof T = keyof T> = Omit<T, Keys> & | |
{ [K in Keys]-?: Required<Pick<T, K>> & Partial<Omit<T, K>> }[Keys]; | |
type RequireOnlyOne<T, Keys extends keyof T = keyof T> = Omit<T, Keys> & | |
{ [K in Keys]: Required<Pick<T, K>> & Partial<Record<Exclude<Keys, K>, undefined>> }[Keys] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment