title: In typescript, how do you express the type of an object where one of the fields is the name of the type?
body: <p>I'm dealing with an event payload where the <code>event</code> field is a string, and the <code>data</code> field is conditional on the <code>event</code> field. I've made a representation that works but feels this isn't the canonical way:</p>
  <pre><code>type EventMap = {
    created: { created: string },
    updated: { updated: string }
  }
  
  type Payload&lt;T extends keyof EventMap&gt; = {
    event_id: string;
    event: T;
    data: EventMap[T];
  };
  
  type Payloads = Payload&lt;'created'&gt; | Payload&lt;'updated'&gt;
  </code></pre>
  <p>It feels like I should not be repeating <code>created</code> and <code>updated</code>. But of course <code>Payload&lt;keyof EventMap&gt;</code> isn't quite right since it will allow any combination.</p>