strict Mode
strict is a single tsconfig.json option that switches on the whole family of strict type-checking flags at once. It is unrelated to JavaScript's "use strict" directive, which is a runtime feature.
Detailed Explanation
Clear up the name collision first, because it causes real confusion. JavaScript's "use strict" is a string at the top of a file or function that changes how the engine executes code at runtime — no implicit globals, this is undefined in plain functions, assignments to frozen objects throw. TypeScript's strict is a compiler option that changes how thoroughly your source is checked before it becomes JavaScript. Different layer, different effect. They touch in exactly one place: strict turns on alwaysStrict, which makes the compiler emit "use strict" into your output.
TypeScript shipped without most of its strictness. The early goal was to accept existing JavaScript, so null was assignable to everything and unannotated parameters were tolerated. Each stricter check arrived later as its own flag. strict is the umbrella that enables the current set, and it is what tsc --init writes into a new config.
What it turns on today:
| Flag | What it catches |
|---|---|
strictNullChecks | null and undefined used where a real value is required |
noImplicitAny | parameters and expressions the compiler cannot infer a type for |
strictFunctionTypes | function parameters compared unsoundly (contravariance) on function type positions |
strictBindCallApply | wrong arguments passed through bind, call, and apply |
strictPropertyInitialization | class fields that are never assigned in the constructor |
noImplicitThis | this in a function where its type cannot be determined |
useUnknownInCatchVariables | catch (e) treated as any instead of unknown |
alwaysStrict | parses files as strict ECMAScript and emits "use strict" |
The list is not frozen. New releases occasionally add a flag to the family, so upgrading the compiler with "strict": true can surface new errors. That is the trade you accept, and it is usually worth it — the errors are real.
Note what strict does not include: noUncheckedIndexedAccess, noImplicitReturns, noFallthroughCasesInSwitch, exactOptionalPropertyTypes, noPropertyAccessFromIndexSignature. These are opt-in separately. Several teams consider noUncheckedIndexedAccess the most valuable flag outside the family, because it makes arr[0] return T | undefined, which is the truth.
For new projects, turn strict on from the first commit. Adding it later is the painful path, because a mature untyped codebase can produce thousands of errors, most of them from strictNullChecks.
For an existing codebase, the workable migration is incremental. Set "strict": true and then explicitly set the individual flags you are not ready for back to false. This inverts the default: everything new is strict, and you delete an exception line at a time. Work flag by flag rather than file by file — noImplicitThis and strictBindCallApply are usually a day's work, strictNullChecks is the long one. Another option is per-directory configs with extends, letting newer code run strict while legacy directories lag.
The cost is engineering time and some genuinely awkward code around values the type system cannot verify. The benefit is that the checks catch the class of bug that dominates JavaScript production incidents: something was undefined and nobody looked.
Code Examples
1. A new project. tsc --init writes this; keep it.
// 1. A new project. tsc --init writes this; keep it.
{
"compilerOptions": {
"target": "ES2022",
"module": "NodeNext",
"strict": true,
// Not part of "strict" — worth enabling deliberately.
"noUncheckedIndexedAccess": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true
}
}2. Migrating an existing codebase: strict on, exceptions listed and deleted over time.
// 2. Migrating an existing codebase: strict on, exceptions listed and deleted over time.
{
"compilerOptions": {
"strict": true,
"strictNullChecks": false, // TODO: ~1,400 errors, tackle module by module
"strictPropertyInitialization": false // depends on strictNullChecks; re-enable together
}
}3. What the family actually catches, one example per flag.
// 3. What the family actually catches, one example per flag.
function len(s: string | null) {
return s.length;
// strictNullChecks: 's' is possibly 'null'.
}
function slug(input) {
// noImplicitAny: Parameter 'input' implicitly has an 'any' type.
return input.toLowerCase();
}
class Session {
userId: string;
// strictPropertyInitialization: Property 'userId' has no initializer
// and is not definitely assigned in the constructor.
}
try {
JSON.parse("{");
} catch (err) {
console.log(err.message);
// useUnknownInCatchVariables: 'err' is of type 'unknown'.
// Narrow it first: if (err instanceof Error) console.log(err.message);
}Common Gotchas
`strict` is not JavaScript's `"use strict"`
one is a compile-time checking level, the other is a runtime execution mode. Turning on TypeScript's `strict` does not change how any existing JavaScript behaves, apart from emitting the `"use strict"` prologue.
Order matters in `tsconfig.json` only through `extends`, not within one object
setting `"strict": true` and `"strictNullChecks": false` in the same `compilerOptions` works regardless of line order, because the specific flag always wins over the umbrella. Do not rely on reordering keys to change behaviour.
Upgrading the compiler can add errors under `strict`
the family gains members across releases. Pin the `typescript` version in your lockfile and treat compiler upgrades as their own change, not a drive-by dependency bump.
`strict` checks nothing at runtime
every check is erased. Data crossing your program's boundary still needs validation, no matter how many flags are on.