Use unknown for External Data (APIs, JSON)

unknown is safer than any.
It forces you to validate the type before using it.

Bad (API response)

const response: any = await fetchData();
response.toUpperCase(); // may crash

Good

const response: unknown = await fetchData();

if (typeof response === "string") {
  response.toUpperCase(); // safe
}

More on TypeScript

Recent Tips