title: How to selectively assign from one Partial to another in typescript
body: <p>In the TypeScript code snippet below, I need to assign from one object to another where both of them are <code>Partial&lt;InjectMap&gt;</code>. Here, my intuition says that typescript should be able to understand what is going on because at line (B), the type of <code>key</code> is <code>typeof InjectMap</code>. So, it should be able to assign values from <code>input</code> to <code>output</code> correctly.</p>
  <pre><code>
  export interface InjectMap {
      &quot;A&quot;: &quot;B&quot;,                          // line (A)
      &quot;C&quot;: &quot;D&quot;
  }
  type InjectKey = keyof InjectMap;
  
  const input: Partial&lt;InjectMap&gt; = {};
  const output: Partial&lt;InjectMap&gt; = {};
  const keys: InjectKey[] = []
  
  for (let i = 0; i &lt; keys.length; i++) {
      const key = keys[i]                // line (B)
      output[key] = input[key]           // line (C)  - Gives Error
  }
  </code></pre>
  <p><a href="https://www.typescriptlang.org/play?#code/FAUwHgDg9gTgLgAgJYDs4hgMwIYGMQICSKAViLnALLYQIDewCTCARAIIsBcrAQiwDSNmLAMJdWAERbAAvsDgBPCAWJkKAaRAKEAXgQBrLVExFS5KjQDcwYLigoAzolQQArnG4AFbPCTYANgA8qubUEAB8uvQy1naOiFDubh4I3r4BwWYUYZF6dDG29k4GWg7cIRpaANoAulG1NsCYsAgAFP4gzlEADJbICIElCg4AdB0oAOZwABZ9SADU8wCU9EJMccWG2npbDlVINWsIiXDJVVt1ei7u51qHckA" rel="nofollow noreferrer">Playground Link</a></p>
  <p>But it gives the following error at line (C):</p>
  <pre><code>Type '&quot;B&quot; | &quot;D&quot; | undefined' is not assignable to type 'undefined'.
    Type '&quot;B&quot;' is not assignable to type 'undefined'.
  </code></pre>
  <p>Strangely, the error goes away if I comment line (A). Is this a shortcoming in TypeScript or am I missing something?</p>