title: Restricting object key type with const
body: <p>I am able to define an object key type from a union like:</p>
  <pre><code>type Action = 'foo' | 'bar' | 'baz';
  
  type UserStates = 'active' | 'deleted' | 'dishonoured';
  
  type Permission = {
    [key in UserStates]: Action[];
  };
  </code></pre>
  <p>However, I have a scenario where the options are const literals like:</p>
  <pre><code>const UserStates = ['active', 'deleted', 'dishonoured'] as const;
  const Action = ['foo', 'bar', 'baz'] as const;
  
  type Permission = {
    [key: typeof UserStates[number]]: typeof Action[number][];
  };
  </code></pre>
  <p>This results in:</p>
  <pre><code>error TS1337: An index signature parameter type cannot be a literal type or generic type. Consider using a mapped object type instead.
  </code></pre>
  <p>How should I define the key signature if this scenario?</p>
  <p>Working Example for union types:</p>
  <pre><code>type Action = 'foo' | 'bar' | 'baz';
  
  type UserStates = 'active' | 'deleted' | 'dishonoured';
  
  type Permission = {
    [key in UserStates]: Action[];
  };
  
  export const PERMISSIONS: Permission = {
    active: ['foo', 'bar', 'baz'],
    deleted: ['bar'],
    dishonoured: ['baz'],
  };
  
  const hasPermission = (userState: UserStates, action: Action): boolean =&gt;
    PERMISSIONS[userState].some((x) =&gt; x === action);
  
  console.info(hasPermission('active', 'foo'));
  console.info(hasPermission('deleted', 'foo'));
  </code></pre>