title: Type checking the API response in typescript
body: <p>I'm curious what happens when you expect a certain type as a response from fetch / Axios / etc and its response is of a different type. Can i detect that mismatch?</p>
  
  <pre><code>interface HttpResponse&lt;T&gt; extends Response {
    parsedBody?: T;
  }
  export async function http&lt;T&gt;( request: RequestInfo ): Promise&lt;HttpResponse&lt;T&gt;&gt; {
    const response: HttpResponse&lt;T&gt; = await fetch( request );
    response.parsedBody = await response.json();
    return response;
  }
  
  // example consuming code
  const response = await http&lt;number&gt;(
    "https://thisURLdoesNotReturnANumber"
  );
  </code></pre>
  
  <p>Will the code throw an error? Will it pass silently? How do i detect a mismatch?</p>