title: Hot to fix "Type 'undefined' is not assignable to type 'T[Extract<keyof T, string>]'"?
body: <pre class="lang-js prettyprint-override"><code>function copyFields&lt;T&gt;(target: T, source: Partial&lt;T&gt;): T {
      for (let id in source) {
          target[id] = source[id];  // Error
      }
      return target;
  }
  
  let x = { a: 1, b: 2, c: 3, d: 4 };
  
  copyFields(x, { b: 10, d: 20 });
  
  </code></pre>
  <p>Code above occurs the error <code>Type 'T[Extract&lt;keyof T, string&gt;] | undefined' is not assignable to type 'T[Extract&lt;keyof T, string&gt;]'. Type 'undefined' is not assignable to type 'T[Extract&lt;keyof T, string&gt;]'</code>.</p>
  <p>Doesn't <code>source</code> always a part of <code>target</code>?</p>
  <p>What's the problem?</p>