title: How to get keyof individual item in a generic array?
body: <p>I am scratching my head around how to implement a generic array such that each item in the array is validated against its own keys. I have few objects that implement a common type plus their own set of properties:</p>
  <pre class="lang-js prettyprint-override"><code>type Table&lt;T&gt; = {
    id: number
    name: string
  } &amp; T
  
  const A: tA = { // tA extends Table
    id: 1,
    name: 'table1',
    prop1: 'hello',
    prop2: 'world'
  };
  
  const B: tB = { // tB extends Table
    id: 1,
    name: 'table2',
    foo: 'baz',
    bar: 'daz'
  };
  </code></pre>
  <p>Then I have a function that takes a list of maps from one table to another:</p>
  <pre><code>type Map&lt;T, S&gt; = {
    name: string,
    map: {
      from: keyof T,
      to: keyof S
    }
  }
  
  const doSomething = &lt;T&gt;(maps: Map&lt;T, S&gt;[]) =&gt; {}
                                   // ^^^ how to make this dynamic for each item?
  </code></pre>
  <p>Now how do I make typescript validate that each item I pass in the array only has the key of its own, not something else? Something like:</p>
  <pre class="lang-js prettyprint-override"><code>doSomething&lt;tC&gt;([  // tC extends Table
    &lt;tB&gt;{
      name: 'map1',
      map: {
        from: 'cProp1'
        to: 'foo'    // pass as foo is in tB
      }
    },
    &lt;tA&gt;{
      name: 'map1',
      map: {
        from: 'cProp1',
        to: 'bar'    // fail as bar is not in tA
      }
    }
  ])
  </code></pre>
  <p>Any help would be much appreciated. Thanks in advance.</p>