Created
December 14, 2018 00:40
-
-
Save jasonrhodes/2a9646f82907982f85f6342e1398158c 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 Neverize<T, U> = { [P in Exclude<keyof T, keyof U>]?: never }; | |
type ExclusiveOr<T, U> = (T | U) extends object | |
? (Neverize<T, U> & U) | (Neverize<U, T> & T) | |
: T | U; | |
interface S { | |
value: string; | |
string: string; | |
} | |
interface N { | |
value: number; | |
number: string; | |
} | |
function what(x: ExclusiveOr<S, N>) { | |
return x.value; | |
} | |
what({ value: 'asdf', string: 'asdf' }); | |
what({ value: 5, string: 'asdf' }); | |
what({ value: 5, number: 'asdf' }); | |
what({ value: 'asdf', number: 'asdf' }); | |
what({ value: 'asdf', string: 'asdf', number: 'asdf' }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment