title: Selecting element from typescript union by its value
body: <p>I have union of such shape:</p>
  
  <pre class="lang-js prettyprint-override"><code>type Message = 
    | { type: 'first', someParam: any } // let it be AMsg
    | { type: 'second', someAnotherParam: any, andOneAnother: any }
  </code></pre>
  
  <p>I want to get an element of this union as a separate type like so:</p>
  
  <pre class="lang-js prettyprint-override"><code>type AMsg = MessageOfType&lt;'first'&gt; // = { type: 'first', someParam: any }
  </code></pre>
  
  <p>I've tried to write my own MessageOfType:</p>
  
  <pre class="lang-js prettyprint-override"><code>type MessageOfType&lt;T extends Message['type']&gt; = Message['type'] extends T ? Message : never
  </code></pre>
  
  <p>but it allways returns <code>never</code>.</p>
  
  <p>What should I use to get an element or some elements with <code>type</code> matching needed value from union?</p>