title: Casting dates properly from an API response in typescript
body: <p>I have a REST API that gives data in the following format:-</p>
  <p><code>{&quot;id&quot;: 1, &quot;name&quot;: &quot;New event&quot;, &quot;date&quot;: &quot;2020-11-14T18:02:00&quot;}</code></p>
  <p>And an interface in my frontend React app like this:-</p>
  <pre><code>export interface MyEvent {
    id: number;
    name: string;
    date: Date;
  }
  </code></pre>
  <p>I use axios to fetch response from the API.</p>
  <pre><code>const response = await axios.get&lt;MyEvent&gt;(&quot;/event/1&quot;);
  const data = response.data;
  </code></pre>
  <p>However, <code>data.date</code> remains a string due to typescript limitations.</p>
  <p>This can cause problems later in the code, where I expect all such date fields to be an actual Date object.</p>
  <p>I could probably do something like: <code>data.date = new Date(data.date);</code>. But that won't be feasible approach for a lot of reasons.</p>
  <p>Is there a better way of handling dates in typescript? How do you handle dates coming from API in response in general?</p>