title: Destructuring of union types in typescript
body: <p>Is there a way (similar to pattern matching from functional languages) to destructure a union type in TypeScript, i.e. some construct like:</p>
  
  <pre><code>var a: Foo | Bar = ...;
  
  a match {
     case f: Foo =&gt; //it's a Foo!
     case b: Bar =&gt; //it's a Bar!
  }
  </code></pre>
  
  <p>If there is no such construct - are there any technical difficulties in creating such construct?</p>