TypeScript · Migration · Frontend · Backend
Migrating an Existing Project to TypeScript Strict Mode, Step by Step
Turning on strict mode in a large TypeScript project without drowning in errors: the order to enable flags, a strictNullChecks strategy, and making the migration stick.

Adding "strict": true to an old project and seeing thousands of errors is demoralising. But most of what strict mode catches are real bugs that otherwise show up in production as Cannot read properties of undefined. Here is how we moved enterprise Angular projects to strict mode without stopping the team.
strict is not one flag
strict: true turns on a group of flags together. The most important:
| Flag | What it catches |
|---|---|
noImplicitAny | Untyped values silently treated as any |
strictNullChecks | Unchecked use of values that may be null/undefined |
strictFunctionTypes | Unsafe type assignments in function parameters |
strictPropertyInitialization | Class fields not initialised in the constructor |
useUnknownInCatchVariables | Makes e in catch (e) unknown |
Turning them on one at a time keeps the migration manageable.
Recommended order
noImplicitAny: usually the easiest. Add missing parameter types; useunknownwhere a type truly isn't known.strictFunctionTypes,strictBindCallApply: few errors.useUnknownInCatchVariables: add aninstanceof Errorcheck before using the error.strictNullChecks: the biggest and most valuable step; plan it separately.strictPropertyInitialization: noisy in Angular because of@Inputand@ViewChildfields; signal-basedinput()andviewChild()remove most of the problem.
Enabling strictNullChecks file by file
Instead of flipping it for the whole project at once, check new and fixed files with a separate config:
// tsconfig.strict.json
{
"extends": "./tsconfig.json",
"compilerOptions": { "strict": true, "noEmit": true },
"files": [],
"include": ["src/app/runs/**/*.ts", "src/app/shared/utils/**/*.ts"]
}
Run tsc -p tsconfig.strict.json in CI and grow the include list every sprint. When it covers the whole project, enable strict: true in the main config and delete this file.
Typical fixes
// Before
const device = devices.find((d) => d.id === id);
return device.name; // device may be undefined
// After
const device = devices.find((d) => d.id === id);
if (!device) throw notFound('Device');
return device.name;
- Early returns and guards fix most errors readably.
- Optional chaining (
user?.profile?.email) only where the value really is optional. - Non-null assertions (
!) are a last resort; each one should be explainable as "this is never null here because...".
Fighting any
Strict mode doesn't ban any; it only catches the implicit kind. Flag explicit any with the ESLint rule @typescript-eslint/no-explicit-any, and for external data use unknown plus schema validation instead. I show how to write flexible code without any in the TypeScript generics guide.
Making it stick
- Don't let new files fall outside strict checking; the CI check guarantees it.
- Use
// @ts-expect-errorinstead of// @ts-ignore: when the issue is fixed, the comment itself errors and gets removed. - Track how many files are strict with a simple metric; seeing progress motivates the team.
Conclusion
Moving to strict mode isn't one big PR but a process that advances flag by flag and folder by folder. What you get at the end is a whole class of bugs caught before they ever reach production.


