Course contentsShow
← TypeScript
Lesson 1189 of 1,79628. tsconfig in DepthFree lesson

Enabling strict Incrementally

Strategies for adopting strict mode in existing codebases one flag at a time.

Enabling strict Incrementally

What you'll learn: How to adopt TypeScript's strict mode in an existing codebase by enabling individual compiler flags one at a time, rather than all at once.

The Challenge of Adopting strict

When you have an existing TypeScript codebase that wasn't built with strict: true, flipping that single switch can instantly reveal hundreds or even thousands of type errors. This is overwhelming and blocks development.

The incremental approach lets you gain strict mode's benefits gradually by enabling each underlying flag separately, fixing errors one category at a time.

The Individual Flags Behind strict

Remember that strict: true is actually a shorthand that enables multiple flags:

  • noImplicitAny
  • strictNullChecks
  • strictFunctionTypes
  • strictBindCallApply
  • strictPropertyInitialization
  • noImplicitThis
  • alwaysStrict
  • useUnknownInCatchVariables

Each can be toggled independently.

Recommended Migration Order

Start with the easiest wins:

  1. alwaysStrict — Just adds "use strict" to output; no type errors
  2. noImplicitAny — Forces explicit parameter types; often reveals real bugs
  3. strictBindCallApply — Type-checks .bind(), .call(), .apply() properly
  4. noImplicitThis — Requires explicit this typing in functions
  5. strictNullChecks — The big one; makes null/undefined explicit (most errors)
  6. strictFunctionTypes — Enforces contravariance; rare breaking changes
  7. strictPropertyInitialization — Requires class properties to be initialized
  8. useUnknownInCatchVariables — Changes catch (e) from any to unknown

The Process

Enable one flag, fix all resulting errors in that category, commit, then move to the next. This keeps pull requests manageable and lets you learn each strictness feature deeply before moving on.

Analogy: It's like tightening security on a building one floor at a time—you can still operate while improving, rather than locking everything down overnight and blocking all access.

Key Takeaway: Adopt strict mode incrementally by enabling and fixing individual compiler flags one at a time, making migration manageable in large codebases.