Created
April 9, 2021 20:23
-
-
Save bamorim/b260cb99c2a463348450f9fb9647d40c to your computer and use it in GitHub Desktop.
xorts
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 XOR<T, U> = (T | U) extends object | |
? (Without<T, U> & U) | (Without<U, T> & T) | |
: T | U | |
type Without<T, U> = { | |
[P in Exclude<keyof T, keyof U>] | |
? | |
: never | |
} | |
type WithHeight = { height: number } | |
type WithWidth = { width: number } | |
type OtherProps = { color?: string } | |
type Props = OtherProps & XOR<XOR<WithHeight, WithWidth>, {}> | |
const p1: Props = { color: "aaa" } | |
const p2: Props = { color: "aaa", width: 1 } | |
const p3: Props = { color: "aaa", height: 1 } | |
const perr: Props = { color: "aaa", height: 1, width: 1 } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment