title: Typescript dynamic types declarations
body: <p>I am trying to fix these errors and don't know how to do it. If you are an expert in the TS please help me with it. <a href="https://www.typescriptlang.org/play?#code/MYewdgzgLgBAhjAvDA3gWAFA3gLhgcgDc4AbAVwFMYBGfAGk2wCM8jTKYAmexmYPdFmwwA1q2LkqAZny8AvpjkBuTJigBPAA5UA8kwBWAFS1VkG7SABm8FRkyWyYYFACW4GA7ABBAE4+46gA8vADSMBQAHlAUYAAmEKIU6lYwekYmSInJ1mnG2nQwvAAi4VEx8akGeRQA2iEAupm5JnX1mAB8ABRwPgDmeHUFIkkpRfUAlKi8oJCw4BQAMoQkmXA1Pb01AAz19ba8APQHMACSEBAcAMQ00+DQMBAUM7FLK8jzr+t9NdS7ttgzCAgEgUAB0JBAvU6j2er3GtgUGE8vn86k6NXwwHoBBE+Am+wwRxgAHUQD4RAk4AlItpnBRYvZHCiAujMdj8Lj8apCcczhcqNdOIzvH4WRi4OzOfDMEA" rel="nofollow noreferrer">https://www.typescriptlang.org/play?#code/MYewdgzgLgBAhjAvDA3gWAFA3gLhgcgDc4AbAVwFMYBGfAGk2wCM8jTKYAmexmYPdFmwwA1q2LkqAZny8AvpjkBuTJigBPAA5UA8kwBWAFS1VkG7SABm8FRkyWyYYFACW4GA7ABBAE4+46gA8vADSMBQAHlAUYAAmEKIU6lYwekYmSInJ1mnG2nQwvAAi4VEx8akGeRQA2iEAupm5JnX1mAB8ABRwPgDmeHUFIkkpRfUAlKi8oJCw4BQAMoQkmXA1Pb01AAz19ba8APQHMACSEBAcAMQ00+DQMBAUM7FLK8jzr+t9NdS7ttgzCAgEgUAB0JBAvU6j2er3GtgUGE8vn86k6NXwwHoBBE+Am+wwRxgAHUQD4RAk4AlItpnBRYvZHCiAujMdj8Lj8apCcczhcqNdOIzvH4WRi4OzOfDMEA</a></p>
  <p><a href="https://i.stack.imgur.com/B0UZb.png" rel="nofollow noreferrer">Image of the code</a></p>
  <pre><code>  const a = {
    a: 'value 1',
    b: 'value 2',
    c: {
      k: 'value 3'
    }
  };
  
  type ObjType = typeof a;
  
  function funArray&lt;
    K extends keyof ObjType = keyof ObjType, 
    D extends ObjType[K] = ObjType[K]
  &gt;(arg: [K, keyof D]) {
    const oneLvl = a[arg[0]];
  
    // Issue # 1
    // Type 'keyof D' cannot be used to index type '{ a: string; b: string; c: { k: string; }; }[K]'.
    const secondLvl = oneLvl[arg[1]];
    console.log(secondLvl);
  }
  funArray(['c', 'k']);
  
  // Works as expected
  funArray(['c', 'k']);
  
  // Issue # 2
  // Type '&quot;k&quot;' is not assignable to type 'number | &quot;toString&quot; | &quot;charAt&quot; | &quot;charCodeAt&quot; | &quot;concat&quot; | &quot;indexOf&quot; | &quot;lastIndexOf&quot; | &quot;localeCompare&quot; | &quot;match&quot; | &quot;replace&quot; | &quot;search&quot; | &quot;slice&quot; | &quot;split&quot; | &quot;substring&quot; | &quot;toLowerCase&quot; | ... 27 more ... | &quot;padEnd&quot;'.
  funArray(['a', 'k']);
  </code></pre>