title: How to define an object type with dynamic keys in TypeScript?
body: <p>I have a const object which looks like this:</p>
  <pre><code>export const Language: Values = {
    es: {urlValue: 'es', label: 'Spain'},
    en: {urlValue: 'en', label: 'Anything'},
    eb: {urlValue: 'eb', label: 'Other thing'},
  };
  
  export interface Values {
    [name: string]: Value;
  }
  
  export interface Value {
    urlValue;
    label;
    selected?;
  }
  </code></pre>
  <p>Now somewhere in app, we read some data which has this format, which coincidentally has the exact same keys:</p>
  <pre><code>{
    es: 32,
    en: 11,
    eb: 56
  }
  </code></pre>
  <p>So actually i need another object type like this:</p>
  <pre><code>export class AnotherObject {
  
    constructor(public es: number,
                public en: number,
                public eb: number) {
    }
  }
  </code></pre>
  <p>But can i create this type also dynamically so that it automatically uses the keys of the Language object, or urlValue of &quot;Value&quot; type?</p>
  <p>PS: The question is a simplified form of our exact use case, where we have multiple consts like Languages. So an automatism would be really helpful.</p>
  <p><strong>Edit</strong>: For the suggestion of @basarat - Since this object is a part of a parent object i actually need a type definiton in this part:</p>
  <pre><code>export class ParentObject {
    thatObjectAbove: AnotherObject;
    otherObjects: ..
    ..
  }
  
  export interface AnotherObject {
    [name: LanguageOptions]: number;
  }
  </code></pre>
  <p>I have the error &quot;An index signature parameter type cannot be a union type. Consider using a mapped object type instead.&quot; on the 'name' part of line &quot;[name: LanguageOptions]: number;&quot;</p>