title: React.js and Typescript return type of a fetch API Response?
body: <p>is it somehow possible to check the response type of a fetch API request on runtime? As far as I know, <code>Response</code> is always any? Is it possible to throw an error in case it does not match the type or else accept the data? Here is my code:</p>
  <pre><code>import React, { useEffect, useState } from 'react';
  import logo from './logo.svg';
  import './App.css';
  
  type Test = {
    name: string;
    age?: number;
  }
  
  interface TodoData {
    id: number,
    userId: number,
    title: string,
    completed: boolean,
  }
  
  type JSONResponse = () =&gt; {
      ok?: boolean,
      status: 200 | number,
      json: () =&gt; Promise&lt;TodoData&gt; | Promise&lt;TodoData&gt;[];
  }
  
  const App: React.FC&lt;Test&gt; = ({name, age}) =&gt; {
    const [todos, setTodos] = useState(null);
  
    useEffect(() =&gt; {
      const fetchData: any = async () =&gt; {
        let todos: Response = await fetch('https://jsonplaceholder.typicode.com/todos');
        console.log(todos);
        let todoData: JSONResponse = await todos.json();
        console.log({todoData});
      }
      fetchData();  
    },[])
  
    return (
      &lt;div className=&quot;App&quot;&gt;
        &lt;p&gt;Hello {name} your age is {age? age: &quot;not given here.&quot;}&lt;/p&gt;
      &lt;/div&gt;
    );
  }
  
  export default App;
  </code></pre>