0Pricing
TypeScript Academy · Lesson

Fetch API types; Response.json() generics

Use the Fetch API with correct types, and Response.json () generics to safely parse JSON payloads.

Intro

Goal: Call APIs with fetch, handle responses safely, and use generics with Response.json().

Basic fetch

fetch returns a Promise<Response>. Use res.text() for plain text bodies.

async function getText() {
  const res = await fetch("/hello.txt");
  const text = await res.text();
  console.log(text);
}

All lessons in this course

  1. Fetch API types; Response.json() generics
  2. Runtime validation with zod (intro)
← Back to TypeScript Academy