TypeScript Reference ยท tsconfig: Type Checking Options
TypeScript strict option
Reference for the TypeScript strict compiler option: the family of flags it enables, how to opt out of one, what changed per version, and what each flag catches.
"strict": true is a single switch that turns on a family of type-checking flags. Each flag catches a distinct class of bugs: values that may be null, parameters whose type was never stated, methods that lose their this, and so on. New projects should always start with strict on; for existing JavaScript migrations you can switch it on and then turn individual flags off while you fix the errors.
Because strict means "the recommended strict set for this version of TypeScript", the exact list can grow in later releases. That is deliberate: upgrading may surface new errors, and you can pin the old behavior by setting the new flag to false explicitly.
{ "compilerOptions": { "strict": true, "noImplicitAny": true, "strictNullChecks": true } }
Try it
This site compiles every example with --strict, so you can see its effects directly.
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or readFileSync(0)), it gets the next line from this box.
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or readFileSync(0)), it gets the next line from this box.
Syntax
{ "compilerOptions": { "strict": true, "strictNullChecks": false } }
tsc --strict tsc --strict --noImplicitThis false
Flag enabled by strict |
Effect |
|---|---|
noImplicitAny |
Error when a type would be inferred as any. |
strictNullChecks |
null and undefined are separate types. |
strictFunctionTypes |
Function parameters are compared contravariantly. |
strictBindCallApply |
bind, call and apply are checked against the function's signature. |
strictPropertyInitialization |
Class fields must be assigned in the constructor. |
noImplicitThis |
Error when this has an implicit any type. |
useUnknownInCatchVariables |
catch (e) gives e the type unknown, not any. |
alwaysStrict |
Emits "use strict" and parses in strict mode. |
strictBuiltinIteratorReturn |
Built-in iterators return undefined instead of any when done (TypeScript 5.6 and later). |
noImplicitOverride is not part of it |
It is a separate flag you opt into. |
Edge cases: a flag set explicitly always wins over strict, in either order in the file. strict: false with individual flags on is allowed.
Usage notes
- Turn it on from day one. Retrofitting
strictNullChecksinto a large codebase is the biggest chunk of migration work; do it flag by flag if you must. - Stricter, but not complete. Flags like
noUncheckedIndexedAccess,exactOptionalPropertyTypes,noImplicitOverrideandnoFallthroughCasesInSwitchare not instrict; many teams add them on top. strictfollows the compiler. TypeScript 7 and the 5.x line each added or tightened flags; read the release notes when upgrading and check which new errors appear.- Escape hatches.
// @ts-expect-errorfor one line with a reason,asassertions for places you know better. Avoid blanketany. - Per-project settings. In a monorepo, share one base
tsconfigwithstrict: trueand extend it. - The CLI flag and the tsconfig field are the same option:
--strictequals"strict": true.