Enabling TypeScript strict mode in an established project does not have to be a one-day rewrite. This phased checklist shows how to assess the codebase, adopt strict compiler options in a manageable order, triage errors by cause, and use temporary escape hatches without allowing them to become permanent debt.
Overview
TypeScript strict mode is a group of compiler checks that makes the type system more precise. In a new project, enabling it early is usually straightforward. In a mature JavaScript-to-TypeScript migration or framework application, however, turning on every check at once can produce a large and confusing error list.
The safer approach is incremental adoption. Keep the application runnable, enable one meaningful group of checks at a time, fix errors by category, and prevent new code from lowering the project’s type-safety baseline. The exact set of options included by strict can expand as TypeScript evolves, so treat your installed TypeScript version and its compiler documentation as the final authority.
Before starting, create a branch and record a baseline:
npx tsc --noEmit
npm test
npm run build
These commands establish whether the project already has build or test failures unrelated to strict mode. If the repository uses a framework, run its own production build as well. For example, a Next.js, Vite, or Node project may apply additional checks outside the plain TypeScript compiler.
Checklist by scenario
Scenario 1: A new TypeScript project
- Start with
strict: truein the project’s primarytsconfig.json. - Confirm that the framework, test runner, and build tool actually read that configuration.
- Run the type check and production build before adding application features.
- Add explicit checks for generated code, scripts, tests, and configuration files if they use separate tsconfig files.
- Consider stricter options such as
noUncheckedIndexedAccessseparately. It is useful, but it is not simply a synonym for strict mode and can require broader API changes.
Scenario 2: An existing TypeScript application
- Find every TypeScript configuration used by the repository. Monorepos often have separate configs for an app, a package, tests, and build tooling.
- Run
tsc --showConfigwith the relevant configuration to inspect the effective settings rather than relying only on inherited files. - Turn on
strictNullChecksfirst if the project currently treatsnullandundefinedtoo loosely. Fix data-loading, optional-prop, and lookup code before moving on. - Enable
noImplicitAnynext. Replace inferred implicit types with useful domain types instead of addinganyeverywhere. - Enable the remaining strict checks through
strict: true, or turn them on individually if the team needs to isolate a particular class of errors. - Keep each phase reviewable. A small pull request that fixes one error category is easier to test and revert than a single migration commit touching every file.
Scenario 3: A framework project with separate environments
- Check the framework’s recommended TypeScript configuration and preserve required settings such as JSX, module resolution, and framework-specific plugins.
- Separate application code from generated declarations and build output. Do not solve errors by including generated directories in the migration.
- Type shared boundaries first: route parameters, API responses, form values, environment variables, and component props.
- For React applications, pay particular attention to nullable data during loading states, event handler types, refs, and controlled form values. A typed form model should reflect what the UI can actually receive, not only the final submitted shape.
- For Node.js applications, check request bodies, environment variables, database results, and caught errors at runtime boundaries. TypeScript cannot validate untrusted input by itself; pair static types with runtime validation where needed.
Compiler-option comparison
| Option | What it catches | Migration guidance |
|---|---|---|
strictNullChecks | Use of possibly null or undefined values | Start with API responses, optional properties, array lookups, and framework loading states. |
noImplicitAny | Parameters and declarations whose type becomes implicit any | Type public boundaries first, then callbacks and utility functions. |
strictFunctionTypes | Unsafe function parameter variance in many function types | Review callbacks, event handlers, and adapter functions where parameter types differ. |
strictPropertyInitialization | Class fields that may remain uninitialized | Initialize fields, use definite assignment only when construction guarantees it, or redesign the class. |
noImplicitThis | Unclear or implicit this values | Prefer functions that receive dependencies explicitly or annotate the intended receiver. |
useUnknownInCatchVariables | Assumptions that every caught value is an Error | Narrow with instanceof Error or a project-specific error guard before reading properties. |
noImplicitOverride | Subclass methods that silently replace base methods | Use the override keyword where inheritance is intentional; confirm availability in the project’s TypeScript version. |
What to double-check
Which configuration is authoritative? A framework command may use a different config from your editor or CI job. Make the type-check command explicit, for example tsc -p tsconfig.app.json --noEmit, and document it in the repository scripts.
Are errors real or configuration-related? “Cannot find name” errors can come from missing DOM, Node.js, test, or Web Worker libraries rather than faulty application types. Check lib, types, included files, and installed type packages before changing source code. See the guide to fixing TypeScript “Cannot Find Name” errors for a focused diagnostic path.
Are external boundaries typed honestly? An API response, parsed JSON value, form submission, or environment variable is not safe merely because it has a TypeScript annotation. Use narrowing or runtime validation at the boundary, then pass a reliable type into the rest of the application.
Are assertions hiding the migration? An occasional as assertion may be justified when a framework or library cannot express a known invariant. Prefer a type guard, a validated value, or a better model when the assertion crosses a trust boundary. The related discussion of satisfies, as const, and annotations can help preserve useful literal types without weakening checks.
Do tests and builds use the same assumptions? A passing editor does not prove that CI, a test runner, or a production bundler uses the same compiler settings. Run all relevant commands during each migration phase and inspect source maps if debugging becomes difficult.
Common mistakes
- Enabling every option in one huge pull request. This makes it difficult to distinguish configuration problems from source-code problems. Use a sequence that the team can review and test.
- Replacing every error with
any. This reduces the error count without improving safety. Preferunknownat uncertain boundaries and narrow it before use. - Using non-null assertions everywhere. The
!operator silences the compiler but does not make a value exist at runtime. Fix the control flow or represent the missing state explicitly. - Ignoring optional values in framework code. Data may be absent during the first render, route parameters may be incomplete, and refs may be null. Model those states rather than assuming the final state is present immediately.
- Changing generated files by hand. Correct the generator, schema, or source configuration, then regenerate. Otherwise the next build will erase the fix.
- Allowing suppressions without ownership. If
@ts-ignoreor a broad assertion is necessary temporarily, add a reason, an issue reference when appropriate, and a review date or removal condition.
When to revisit
Return to this checklist whenever the project changes its TypeScript version, framework, module configuration, test runner, or generated-code workflow. A compiler upgrade can expose new checks or alter inference, while a framework upgrade may introduce a new tsconfig or change which files are checked.
Revisit before a seasonal planning cycle or a major refactor. Review the remaining suppressions, search for new uses of any, and confirm that strict checking runs in local development and CI. If the team has finished the initial migration, consider adopting additional options individually, such as noUncheckedIndexedAccess or exactOptionalPropertyTypes, after measuring their effect on the codebase.
A practical final pass is:
- Run the project’s documented type-check command.
- Run unit, integration, and framework-specific build checks.
- Review new suppressions and assertions in the diff.
- Remove one temporary escape hatch while fixing the surrounding model or boundary.
- Record the next strict option or error category for the team to address.
Strict mode is most valuable when it becomes a maintained development habit rather than a one-time migration milestone. Treat the configuration as part of the application’s design, and update the checklist whenever the tools or boundaries change.