title: How to use filter for type narrowing?
body: <p>How can I achieve type narrowing using filter? I was surpsrised to see in the code below that <code>error</code> has type <code>Outcome</code> and not <code>ErrorOutcome</code>.</p>
  <pre><code>type Outcome = ResultOutcome | ErrorOutcome;
  type ResultOutcome = {
    id: string;
    result: string;
  };
  type ErrorOutcome = {
    id: string;
    error: string;
  };
  
  function isErrorOutcome(val: Outcome): val is ErrorOutcome {
    return (val as ErrorOutcome).error !== undefined
  }
  
  function isResultOutcome(val: Outcome): val is ResultOutcome {
    return (val as ResultOutcome).result !== undefined
  }
  
  results.filter(result =&gt; isErrorOutcome(result)).forEach(error =&gt; ...)
  </code></pre>
  <p>Also, a related questions: would it be more Typescript ideomatic to define <code>ResultOutcome</code> and <code>ErrorOutcome</code> as classes and use the <code>instanceof</code> operator instead?</p>