Created
May 14, 2024 03:03
-
-
Save johan/dd216df62fc3ff75c2dace7054af5d84 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/** | |
* Given any object type T, produce a type that requires you to set ONE | |
* of its properties, while forbidding any of the others to also be set. | |
*/ | |
export type RequiresEitherProperty<T extends {}, K extends keyof T = keyof T> = { | |
[P in K]: Record<P, T[P]> & | |
Partial<{ | |
[Y in Exclude<K, P>]: never; | |
}>; | |
}[K]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment