title: Typescript function arguments based on types with enums as keys
body: <p>Lets say that I have an enum with a set of action types:</p>
  <pre><code>export enum ActionTypes {
    action1 = 'action1',
    action2 = 'action2',
    action3 = 'action3',
    // ...etc
  }
  </code></pre>
  <p>And I have a set of payload types that a function wants when performing that action, which is keyed off the action types themselves:</p>
  <pre><code>export type ActionPayloads = {
    [ActionTypes.action1]: boolean,
    [ActionTypes.action2]: string,
    [ActionTypes.action3]: void,
    // ...etc
  }
  </code></pre>
  <p>I want to use a function that takes as its first parameter the action type from the enum, and then use TS hinting to have it infer the payload type for argument two:</p>
  <pre><code>function exampleFn&lt;T extends ActionTypes, U extends ActionPayloads[T]&gt; (type: T, data?: U): void {
    //...
  }
  </code></pre>
  <p>I feel like this would work, but even if I change ActionPayloads to an interface, in both cases for <code>U extends ActionPayloads[T]</code> I get the error <code>TS2536: Type 'T' cannot be used to index type 'ActionPayloads'</code></p>
  <p>Am I missing something here? I feel like this should work, given that there's nothing fancy going on with the usage of the enum.</p>