Skip to main content
TYPESCRIPT-BASICS5 MIN READ

Use unknown at trust boundaries

Replace unsafe `any` at external boundaries with `unknown` plus a narrowing check.

The move: Treat outside data as unknown until checked. The TypeScript Handbook explains that any disables type checking for the value and what flows from it. That means one any at the edge can contaminate a whole function. The linter rule against explicit any exists because the cost is usually paid later, in a review or incident, when no one can tell which assumptions were checked. unknown creates a useful pause. The compiler lets you store the value, pass it to validators, and compare it, but it blocks confident property access. This turns a vague hope into a small decision:…

Read the full lesson

Sign up free — one personalized lesson every day, matched to your role and goals.

Already have an account? Sign in

← Back to library
Contact us