title: Why is this mapped type losing the type inference of the object literal?
body: <p>This is a contrived, but normally I can pass an object literal to a function and capture the values of the literal in a generic, i.e.:</p>
  
  <pre class="lang-js prettyprint-override"><code>type Values&lt;V&gt; = {
    a: V;
    b: V;
  };
  
  function mapValues&lt;V&gt;(v: Values&lt;V&gt;): V {
    return v as any; // ignore
  }
  const vn = mapValues({ a: 1, b: 2 }); // inferred number
  const vs = mapValues({ a: '1', b: '2' }); // inferred string
  </code></pre>
  
  <p>Both <code>vn</code> and <code>vs</code> are correctly inferred to <code>number</code> or <code>string</code> depending on what I passed to <code>mapValues</code>.</p>
  
  <p>This even works for indexed types:</p>
  
  <pre class="lang-js prettyprint-override"><code>function mapValues2&lt;V&gt;(v: { [key: string]: V }): V {
    return v as any;
  }
  const v2n = mapValues2({ a: 1, b: 2 }); // inferred number
  const v2s = mapValues2({ a: '1', b: '2' }); // inferred string
  </code></pre>
  
  <p>The <code>v</code> object literal knows it's values are <code>string</code>/<code>number</code> (respectively), and I'm able to capture that inferred <code>V</code> and use it in the return type.</p>
  
  <p>However, once I use a mapped type, i.e.:</p>
  
  <pre class="lang-js prettyprint-override"><code>enum Foo {
    a,
    b,
  }
  function mapValues3&lt;K, V&gt;(o: K, v: { [key in keyof K]: V }): V {
    return v as any;
  }
  const v3n = mapValues3(Foo, { a: 1, b: 2 }); // inferred unknown
  const v3s = mapValues3(Foo, { a: '1', b: '2' }); // inferred unknown
  </code></pre>
  
  <p>It is like <code>V</code> has forgotten whether it was <code>string</code>/<code>number</code> (respectively), and I get <code>unknown</code> inferred.</p>
  
  <p>Note that if I explicitly type <code>const v3n: number</code> then it works, but I want to rely on type inference to figure <code>V</code> out for me.</p>
  
  <p>I'm confused why change the <code>[key: string]</code> from the 2nd snippet to <code>[key in keyof K]</code> in the 3rd would affect the inference of the <code>: V</code> side of the object literal's type inference.</p>
  
  <p>Any ideas?</p>