Skip to content
RED SAGSkills
medium10 pts · first answer countstypescriptapi-contracts

Type cast on fetch response

The backend renamed fullName to displayName. tsc still passes, but the frontend crashes in production. Why didn’t TypeScript catch it?

type User = { id: string; fullName: string }

const res = await fetch('/api/me')
const user = (await res.json()) as User
render(user.fullName.toUpperCase())
Choose one answer

Discussion 0

Join free to post in the discussion.

Related questions