title: TypeScript Partials: How to map specific fields from an object to another object
body: <p>I'm working on a feature that retrieves a list of products from some E-commerce API.
  I'm trying to add an ability to request specific fields from the products, removing the unnecessary fields.</p>
  <p>This is the code:</p>
  <pre><code>    interface Product {
       images: string[],
       title: string;
       id: number;
       currency: string;
       price: number;
       created: string | Date;
       description: string; 
      }
      
      const getProducts = (selectedProperties: (keyof Product)[]) =&gt; {
  
        // imagine this is a call to an API to get a list of products 
        const products: Product[] = [
                          {
                              id: 1,
                              images: [],
                              title: 'a shirt',
                              currency: &quot;USD&quot;,
                              price: 10,
                              created: &quot;2021-04-29T11:21:53.386Z&quot;,
                              description: &quot;Neque porro quisquam est qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit...&quot;
                           }
                       ];
  
      if(selectedProperties?.length){
          return products.map(product =&gt; {
              const result: Partial&lt;Product&gt; = {};
  
              selectedProperties.forEach(prop =&gt; {
                  result[prop] = product[prop]; // &lt;--- This line returns the error: Type 'string | number | string[] | Date' is not assignable to type 'undefined'. Type 'string' is not assignable to type 'undefined'
              })
  
              return result;
          })
      }
  
      return products;
  }
  </code></pre>
  <p>Here is a link to a code sandbox with the error so you could see it for yourself: <a href="https://codesandbox.io/s/g6uoq?file=/index.ts" rel="nofollow noreferrer">link</a> (look at line 30)</p>
  <p>What am I doing wrong here exactly that is causing the TypeScript error?</p>