TypeScript Classes and Modules/Parse JSON into `unknown` first

Treat external JSON as unsafe until validated.

Section: Errors and Validation Boundaries

Parse JSON into `unknown` first

typescript
typescript
const raw: unknown = JSON.parse(payload);
Explanation

Using `unknown` forces validation before use and is safer than blindly asserting types.

Learn the surrounding workflow

Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.

Related commands

Same sheet · prioritizing Errors and Validation Boundaries
Narrow caught errors
Handle `unknown` errors in catch blocks safely.
OpenIn sheettypescriptsame section
Define a class
Type instance fields and constructor parameters.
OpenIn sheettypescript1 tag match
Named export
Export multiple values from a module.
OpenIn sheettypescript1 tag match
Use access modifiers
Control visibility with `public`, `private`, and `protected`.
OpenIn sheettypescript1 tag match
Default export
Export one primary value from a module.
OpenIn sheettypescript1 tag match
Readonly class fields
Prevent reassignment after construction.
OpenIn sheettypescript1 tag match