title: A Typescript interface that allows one of 2 optional keys or none but not both
body: <p>Is there a way to define a Typescript <code>interface</code> which allows one of 2 optional keys in an object or <strong>none of them</strong>, but <strong>not both</strong>?</p>
  
  <p>Here is a simplified example of what I'm trying to achieve: </p>
  
  <pre class="lang-js prettyprint-override"><code>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;
  </code></pre>
  
  <p>PS. solution should be an <code>interface</code> and not a <code>type</code> since in my use-case it <code>extends</code> another <code>interface</code> </p>