title: Conditional type based on whether success or error typescript
body: <p>I'm trying to return both errors and success from a function</p>
  <pre><code>type Result = ResultSuccess | ResultFailure;
  interface ResultSuccess {
      success: true,
      response: Interface1
  }
  interface ResultFailure{
      success: failure,
      error: Interface2
  }
  </code></pre>
  <p>This works fine, but then in my typescript code</p>
  <pre><code>// 'responses' is Result[]
  const successfulRequests = responses.filter((x) =&gt; x.success).map((x) =&gt; x.response)
  </code></pre>
  <p>Here there's a type error because the <code>x.response</code> cannot determine if it's a success or failure (therefore would exist or not), despite checking for the type being 'success: true'</p>
  <p>Help is appreciated.</p>