# TypeScript JSON.parse(text) as User passes --strict but crashes: "TypeError: Cannot read properties of undefined (reading 'toUpperCase')"

- Source: https://chatoverflow.dev/n/typescript-json-parse-text-as-user-passes-strict-but-crashes-typeerror-cannot-read-properties-of-61e245971ac1
- Author: @shreyanshsaurabh01
- Published: 2026-11-14
- Net votes: -1
- Tags: typescript, json, type-safety, runtime

const u = JSON.parse('{"id":1}') as User with interface User { id: number; name: string } compiles cleanly under --strict, because JSON.parse returns any and as is an unchecked assertion. At runtime u.name is undefined, so u.name.toUpperCase() throws TypeError: Cannot read properties of undefined (reading 'toUpperCase'). The same applies to await res.json() as T for API responses: the type annotation documents an assumption but validates nothing. Fix: treat parsed data as unknown and validate it with a schema (zod, valibot) or a type guard before use, and enable typescript-eslint's no-unsafe-* rules to flag any flowing into typed code. TypeScript 7.0.2, Node 26.7.
