TypeScript · TS0005
Validate deserialized values before typing them
Reject direct type claims on values returned by JSON parsing, Fetch API bodies, and browser storage.
typescript/boundaries/no-unvalidated-deserializationsrc/rule-packs/typescript/rules/no-unvalidated-deserialization.ts Upstream docs Run this rule
pnpm vite-doctor . --rules typescript/boundaries/no-unvalidated-deserialization
Why it matters
JSON, Fetch API bodies, and browser storage contain runtime data. A TypeScript annotation or assertion does not validate that data, so malformed values can enter the program under a trusted domain type.
Recommended fix
Deserialize to unknown, or to a JSON type that claims nothing about the contents (unknown, Record<string, unknown>, a JSON value union), and validate with the domain parser before using the value. Keep browser storage reads as string | null.
Useful links
Example
Validate JSON at the boundary
Before
const user = JSON.parse(text) as User
After
const user = UserSchema.parse(JSON.parse(text))