title: Typescript parameters - a generic array of objects and array of object's keys (partial)
body: <p>I want to have a method that accepts an array of objects and an array of some of the objects keys. The method will return an array of arrays of object values but only of the selected keys.</p>
  
  <p>data: </p>
  
  <pre><code>[
    {"firstName": "Jane", "lastName": "Doe"},
    {"firstName": "John", "lastName": "Doe"}
  ]
  </code></pre>
  
  <p>fields:</p>
  
  <pre><code>["firstName"]
  </code></pre>
  
  <p>result:</p>
  
  <pre><code>[["Jane"], ["John"]]
  </code></pre>
  
  <p>By now I have a function that provides desired outcome but I am not sure how to handle the types better.</p>
  
  <pre class="lang-js prettyprint-override"><code>mapToCsvData: (data: { [key: string]: any }[], fields: string[]) =&gt; {
    return data.map((item: any) =&gt; {
      return fields.map(field =&gt; item[field]);
    });
  }
  </code></pre>
  
  <p>I have tried some variations of the next snippet but I get an error.</p>
  
  <pre><code>mapToCsvData: &lt;T extends object&gt;(data: T[], fields: keyof T[]) =&gt; {
  </code></pre>
  
  <pre><code>Property 'map' does not exist on type 'number'.
  </code></pre>