title: Specify a different type for some keys of a dictionary in Typescript
body: <p>I am trying to do something like that in Typescript :</p>
  
  <pre><code>type A = 'stuff'
  type B = {
    [x: string]: {
      active?: {
        [name: string] : A
      }
      [name: string] : A
    }
  }
  </code></pre>
  
  <p>But I get : <code>Property 'active' of type '{ [name: string]: A; } | undefined' is not assignable to string index type 'A'.</code></p>
  
  <p>What I understand is that <code>active</code> is also recognized as a member of [name: string]. Is there aanything I can do to precise that <code>active</code> might contain something different from the other keys?</p>
  
  <p>I hope this is not a duplicate, I had a hard time finding the good way to describe the problem in Google.</p>
  
  <p>** Update: **</p>
  
  <p>The following code fail with Typescript</p>
  
  <pre class="lang-js prettyprint-override"><code>type ImageName = 'test'
  type IconEntry = { [name: string]: ImageName }
  type Icons = {
    [namespace: string]: IconEntry &amp; {
      active?: IconEntry;
    };
  }
  
  const icons: Icons = {
    buttons: {
      switch: 'test',
      active: {
        switch: 'test'
      }
    }
  }
  </code></pre>
  
  <pre class="lang-js prettyprint-override"><code>Type '{ switch: "test"; active: { switch: "test"; }; }' is not assignable to type 'IconEntry &amp; { active?: IconEntry | undefined; }'.
    Type '{ switch: "test"; active: { switch: "test"; }; }' is not assignable to type 'IconEntry'.
      Property 'active' is incompatible with index signature.
        Type '{ switch: "test"; }' is not assignable to type '"test"'.(2322)
  input.ts(4, 3): The expected type comes from this index signature.
  </code></pre>