---
title: "Migrating an Existing Project to TypeScript Strict Mode, Step by Step"
description: "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."
url: https://sanderyaz.com/en/blog/typescript-strict-mode-migration/
author: Sander Yazıcıoğlu
date: 2026-12-02
updated: 2026-12-02
lang: en
tags: ["TypeScript","Migration","Frontend","Backend"]
---

# Migrating an Existing Project to TypeScript Strict Mode, Step by Step

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

1. **`noImplicitAny`:** usually the easiest. Add missing parameter types; use `unknown` where a type truly isn't known.
2. **`strictFunctionTypes`, `strictBindCallApply`:** few errors.
3. **`useUnknownInCatchVariables`:** add an `instanceof Error` check before using the error.
4. **`strictNullChecks`:** the biggest and most valuable step; plan it separately.
5. **`strictPropertyInitialization`:** noisy in Angular because of `@Input` and `@ViewChild` fields; signal-based `input()` and `viewChild()` 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:

```json
// 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

```ts
// 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](/en/blog/typescript-generics-practical-guide/).

## Making it stick

- Don't let new files fall outside strict checking; the CI check guarantees it.
- Use `// @ts-expect-error` instead 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.

---

About the author: [Sander Yazıcıoğlu](https://sanderyaz.com/en/about/). Sander Yazıcıoğlu is a Senior Full-Stack Developer in Istanbul. At LiveTesting he builds the backend, frontend, realtime systems and Appium automation of a real-device testing platform; before that he built enterprise Angular apps at Testinium and Loadium.
