title: Create an object type out of multiple types
body: <p>I'm trying to figure out how to create an object-based type, which keys are fixed and map to a specific property of a type. The values should use the type which corresponds to the the property.</p>
  
  <p>Consider the following types:</p>
  
  <pre class="lang-js prettyprint-override"><code>interface CooldownError {
    message: 'cooldown'
    minutes: Number
  }
  
  interface AbortError {
    message: 'error'
    description: string
  }
  </code></pre>
  
  <p>Based on the <code>message</code> property, I want a type which has the following signature:</p>
  
  <pre class="lang-js prettyprint-override"><code>type ErrorCollection = {
      cooldown: (e: CooldownError) =&gt; void;
      error: (e: AbortError) =&gt; void;
  }
  </code></pre>
  
  <p>What I tried so far:</p>
  
  <pre class="lang-js prettyprint-override"><code>type GQLErrors = CooldownError | AbortError;
  type ErrorCollection = { [key in GQLErrors['message']]: (e: GQLErrors) =&gt; void };
  </code></pre>
  
  <p>While this works for the keys, all values are set to the union. I didn't find a way to deconstruct the union somehow. Is this even possible?</p>