Course contentsShow
← TypeScript
Lesson 57 of 1,7962. Setup and ToolingFree lesson

strict: The Master Safety Flag

Enabling strict mode to turn on all strict type-checking options at once for maximum type safety.

strict: The Master Safety Flag

You'll learn how enabling strict mode in your tsconfig.json instantly activates all of TypeScript's safety checks with a single setting.

What is Strict Mode?

Think of strict as the "master switch" for type safety in TypeScript. Instead of manually enabling each individual type-checking option one by one, flipping strict to true turns them all on at once.

It's like choosing a car's "maximum safety package" — you get airbags, anti-lock brakes, lane assist, and collision warnings together, rather than ordering each feature separately.

Why Use It?

When you set "strict": true in your compilerOptions, TypeScript becomes much more rigorous about catching potential bugs. It enables checks like:

  • Ensuring you handle null and undefined properly
  • Requiring explicit types in certain situations
  • Preventing accidental use of any type
  • And several other safety features

Without strict mode, TypeScript is more lenient — it allows shortcuts that might hide bugs. With strict mode enabled, you get maximum protection from the type system.

The Configuration

In your tsconfig.json:

{
  "compilerOptions": {
    "strict": true
  }
}

That single line activates multiple safety features simultaneously. As TypeScript evolves, new strict checks may be added, and this flag will include them automatically.

When to Enable It?

Enable strict mode in new projects from day one. It's much easier to write strictly-typed code from the start than to retrofit it later. For existing JavaScript code you're converting, you might temporarily leave it off, then enable it gradually.

Key Takeaway: The strict flag is your one-stop setting for maximum type safety — it enables all strict type-checking options together, giving you the strongest protection TypeScript offers.