title: How to select certain fields in the response body when making http call using TypeScript and Axios
body: <p>I am very new to JavaScript and TypeScript and have always been coding in statically typed language, e.g. Java, Kotlin, Scala.</p>
  <p>So, I am trying to convert a response body received from a http call using Axios to an interface I have defined. See the following code.</p>
  <pre><code>import axios, { AxiosRequestConfig, AxiosResponse } from 'axios';
  
  const token: string = 'token';
  const url: string = 'https://some.api.website.com/users'
  
  interface User {
      id: bigint,
      startDate: string
  };
  
  const axiosRequestConfig: AxiosRequestConfig = {
      headers: { 'Authorization': `Bearer ${token}`}
  };
  
  async function getUsers() {
      return await axios.get(url, axiosRequestConfig)
      .then(res =&gt; res.data)
  };
  
  async function main() {
      let res = await getUsers();
      console.log(res);
  }
  
  main();
  </code></pre>
  <p>The <code>res.data</code> contains something like this. The actual response contains a lot more fields than the example below, hence, why I want to select which fields I need rather than getting them all first.</p>
  <pre><code>[
    {
      &quot;id&quot;: 123456,
      &quot;employment_start_date&quot;: &quot;1989-12-17&quot;,
      &quot;report_department_id&quot;: 111,
      &quot;active&quot;: true,
      &quot;time_zone&quot;: &quot;Australia/Brisbane&quot;,
      &quot;utc_offset&quot;: 36000,
      &quot;created_at&quot;: 1430715548
    }
  ]
  </code></pre>
  <p>How do I parse the response body and cast it to the interface <code>User</code> I defined? In other words, I want to <code>getUsers()</code> function signature to return <code>Promise&lt;User[]&gt;</code>.</p>
  <p>Thanks.</p>