- Sound mode S-14, pre-alpha
- Design record 0007, Accepted
TSR1401
Value from external source '{0}' must be parsed before use: write 'parse<T>({1})' with the type you expect.
A value from JSON.parse, res.json() or another external source is used without validation. Parse it with parse<T>() first.
Rule S-14: Data from outside the program is typed `unknown` until parsed (level: sound). Reported by ts-r-check and ts-r-lsp in files that opt in to sound mode. See Sound mode.
What it means
Values from outside the program (JSON.parse, .json() on Response, MessageEvent.data, server request bodies) are typed unknown in sound files until parsed. They may be stored as unknown and narrowed with typeof, instanceof, in and equality checks; any other use (property access, a call, assignment to a typed target, a typed return, spread, destructuring or a type assertion) is reported.
Example
// Destructuring an external value reads properties off it.
const { theme } = JSON.parse('{"theme":"dark"}'); // @expect TSR1401
export const t: unknown = theme;
How to fix
- Validate it:
const user = parse<User>(JSON.parse(text)), orfetchJson<User>(url). - Use
safeParse<T>to get a result instead of an exception. - Keep it
unknownand narrow it by hand.
Sound mode is defined in design record 0007 (accepted 2026-10-15).