Back to stories
<Frontend/>
Premium

TypeScript for Frontend (Part 4): Strict Mode and Type Narrowing

Share by

TypeScript for Frontend (Part 4): Strict Mode and Type Narrowing

Strict mode in TypeScript turns on a set of checks that catch more bugs at compile time: strict null checks, no implicit any, strict function types, and others. Type narrowing is how the compiler infers a smaller type inside branches (e.g. after if (x !== null)). This post covers enabling strict mode, fixing common issues, and using narrowing and type guards effectively.


What strict mode does

In tsconfig.json, "strict": true enables: