title: Map enum values to individual types in TypeScript
body: <p>I have a piece of TypeScript code like this:</p>
  <pre><code>enum EventType {
    EVENT_A = 'eventA',
    EVENT_B = 'eventB',
    ... // more event types
  }
  
  interface Event {
    type: EventType;
  }
  
  interface EventA extends Event {
    type: EventType.EVENT_A;
    data: PayloadForEventA;
  }
  
  interface EventB extends Event {
    type: EventType.EVENT_B;
    data: PayloadForEventB;
    id: number;
  }
  
  ... // More Event interfaces
  </code></pre>
  <p>Is it possible to somehow map the values of <code>EventType</code> to corresponding interfaces? If it could not be done automatically, is it possible to specify the types mapped by the enum values manually?</p>
  <p>I do know that it is possible to map values to types as shown in <a href="https://stackoverflow.com/questions/48914818/mapping-enum-to-type">this question</a>. And using the method shown below, it could create the lookup table I needed:</p>
  <pre><code>type EventTypeLut = {
    'eventA': EventA,
    'eventB': EventB,
    // ...
  };
  </code></pre>
  <p>But this method hardcodes the value of enum into the LUT. The enum value might change in the future (which I don't have much control) and hardcoding the enum value makes it harder to maintain.</p>
  <p>When I try to use <code>EventType.EVENT_A</code> as key name, TypeScript complains with &quot;property or signature expected&quot;. Using template string seems also no avail. (It seems that the key name cannot be computed, even if it's a constant expression like <code>1+2</code>.)</p>
  <p>The reason I am trying to do this is I would like to create a typed <code>EventEmitter</code> with the enum value of <code>EventType</code> as name and respective typed object for callback function.
  If there is a better way to achieve this, please also give a hint. Thanks in advance.</p>