I'd like to assert that a type can have neither, either, but not both of a pair of properties.
The following does not work, although I'd have assumed it would. Apparently having a: never and b: never means that I have to provide both?
I also tried using {} in place of NeitherANorB which compiled and ran, but did not catch the fourth case where I incorrectly passed both options.
interface JustA {
a: string;
b: never;
}
interface JustB {
a: never;
b: string;
}
interface NeitherANorB {
a: never;
b: never;
}
type NotBothAAndB = JustA | JustB | NeitherANorB;
function testMe(x: NotBothAAndB) {
console.log(x);
}
testMe({}); // OK
testMe({ a: "HI!" }); // OK
testMe({ b: "SUP?" }); // OK
testMe({ a: "HI!", b: "SUP?" }); // NOT OK