title: How to configure a conditional type based on value of a property?
body: <p>I have a number of <code>Item</code> objects and a method that processes them. The issue is that some Items could potentially have certain properties that others don't. </p>
  
  <pre class="lang-js prettyprint-override"><code>type ItemType = 'ApiGateway' | 'ApiGatewayEndpoint' | 'ApiGatewayMethod';
  
  export default interface Item {
      ref?: string;
      position: Position;
      type: ItemType;
      children?: Item[];
  }
  
  function process(item: Item) {...}
  </code></pre>
  
  <p>Now, let's say I want to create a separate interface <code>ApiGatewayMethodItem</code> (that extends <code>Item</code>) that has an additional string property called 'method' representing whether it's a GET or POST or something else. Is there a way I can type it in such a way that as soon as I type <code>process({type: 'ApiGatewayMethod'})</code> tsc will start complaining about the missing property <code>method</code> ? I understand that TS has a pretty good support for the "conditional types", but I haven't used them before and I'm having a hard time wrapping my head around them...</p>
  
  <p>So let's say I have the interface </p>
  
  <pre><code>interface ApiGatewayMethodItem extends Omit&lt;Item, 'type'&gt; {
      type: 'ApiGatewayMethod';
      method: string;
  }
  </code></pre>
  
  <p>now when I call the <code>process</code> function, I need the compiler to complain that the <code>method</code> property is missing when I don't specify it, but specify the type <code>ApiGatewayMethod</code></p>