Is there a way to define a Typescript interface
which allows one of 2 optional keys in an object or none of them, but not both?
Here is a simplified example of what I'm trying to achieve:
const example1 = { foo: 'some string' }; //should pass - can have only "foo: string"
const example2 = { bar: 42 }; // should pass - can have only "bar: number"
const example3 = {}; // should pass - both foo and bar are optional
const example4 = { foo: 'some string', bar: 42 }; // should throw a Typescript error - can't have both foo and bar simultaneously;
PS. solution should be an interface
and not a type
since in my use-case it extends
another interface