title: TypeScript - how to type an object of interfaces with dynamic keys
body: <p>I'm just starting to use typeScript, and I try to type some data I get from my API.</p>
  <p>[EDIT]
  If my API send me an array of &quot;simple&quot; company objects, like that:</p>
  <pre><code>&quot;companies&quot;: [
    {
      &quot;id&quot;: &quot;foo&quot;,
      &quot;label&quot;: &quot;Foo&quot;,
      &quot;someNumber&quot;: 20,
      &quot;someOtherNumber&quot;: 3
    },
    {
      &quot;id&quot;: &quot;bar&quot;,
      &quot;label&quot;: &quot;Bar&quot;,
      &quot;someNumber&quot;: 20,
      &quot;someOtherNumber&quot;: 0
    }
  ]
  </code></pre>
  <p>I would have a <code>CompanyInterface</code> like this:</p>
  <pre><code>export interface CompanyInterface {
    label: string,
    someNumber: number|null,
    someOtherNumber: number,
  }
  </code></pre>
  <p>And I could do this: <code>private companies: Array&lt;CompanyInterface&gt; = [];</code></p>
  <p>BUT, my API send me a list of companies that are objects indexed by dynamic keys:</p>
  <pre><code>&quot;companies&quot;: {
    &quot;foo&quot;: {
      &quot;label&quot;: &quot;Foo&quot;,
      &quot;someNumber&quot;: 20,
      &quot;someOtherNumber&quot;: 3
    },
    &quot;bar&quot;: {
      &quot;label&quot;: &quot;Bar&quot;,
      &quot;someNumber&quot;: 20,
      &quot;someOtherNumber&quot;: 0
    }
  }
  </code></pre>
  <p>And my Interface looks like that:</p>
  <pre><code>export interface CompanyInterface {
    [key: string]: {
      label: string,
      someNumber: number|null,
      someOtherNumber: number,
    }
  }
  </code></pre>
  <p>So what is the best way to type my <code>companies</code> property?</p>
  <p>[info]
  I tried @aleksxor 's answer: <code>private companies: CompanyInterface = {}</code> and I don't have any TS error. Is it what I should keep in my code?</p>