TypeScript Strict Mode: Every Flag, Common Errors and How to Enable It
By Eoin Villarin, 2026-03-28, updated 2026-11-14
What TypeScript strict mode does, every flag "strict": true enables, how to turn it on in an existing codebase step by step, and fixes for the 10 errors you will hit first.
What is TypeScript strict mode and how do I enable it?
TypeScript strict mode is the "strict": true option in tsconfig.json, which turns on nine type checks including strictNullChecks, noImplicitAny and useUnknownInCatchVariables. Add "strict": true under compilerOptions to enable it, or use TypeScript 6.0 or later, where it is on by default. In an existing codebase, enable the flags one at a time and gate the result with tsc --noEmit in CI.
Key takeaways
- "strict": true enables nine flags: strictNullChecks, noImplicitAny, strictFunctionTypes, strictBindCallApply, strictPropertyInitialization, noImplicitThis, alwaysStrict, useUnknownInCatchVariables and strictBuiltinIteratorReturn.
- Strict has been on by default since TypeScript 6.0 (March 2026), and TypeScript 7.0, the native Go compiler released in July 2026, kept that default.
- In an existing project, pin "strict": false, then enable flags one by one, starting with noImplicitAny and strictNullChecks, and only let the @ts-expect-error count go down.
- Most strict errors are possibly undefined values, implicit any parameters and unknown catch variables, fixed with narrowing, annotations and instanceof Error checks.
- noUncheckedIndexedAccess, exactOptionalPropertyTypes and noImplicitOverride are not part of strict but catch extra bugs once strict is clean.
TypeScript strict mode is a single compiler option, "strict": true in tsconfig.json, that turns on a family of nine type checks which catch null and undefined bugs, silent any types, unsafe catch variables and other mistakes before your code runs. To enable it, add "strict": true under compilerOptions, or simply use TypeScript 6.0 or later, where strict is already true by default.
{
"compilerOptions": {
"strict": true
}
}
This guide is current as of November 2026. The latest stable release on npm is TypeScript 7.0.2, the native Go-based compiler, and TypeScript 7.1 is in beta. Below you will find every flag that strict enables, a step-by-step plan for turning it on in an existing codebase, the ten errors you will almost certainly hit with before and after fixes, a recommended tsconfig, and notes for React, Next.js and Node.js.
Is TypeScript strict mode on by default in 2026?
Yes. The TypeScript 6.0 announcement (March 23, 2026) states that strict is now true by default. Before 6.0, a tsconfig with no strict line meant strict was off. Now it means strict is on, and a project that relied on the old behavior has to write "strict": false explicitly to keep it.
TypeScript 6.0 was also the last release built on the old JavaScript codebase. The TypeScript 7.0 announcement (July 8, 2026) shipped the native Go port under the normal typescript package and tsc command. It keeps strict on by default, adopts all the 6.0 defaults, and Microsoft reports full builds that are typically 8 to 12 times faster than TypeScript 6. That speedup removes the old excuse that strict checking makes CI too slow.
What this means for you depends on where your project starts:
- New projects: you get strict mode automatically. Even the TypeScript 5.9
tsc --inittemplate already wrote"strict": true, plusnoUncheckedIndexedAccessandexactOptionalPropertyTypes, according to the 5.9 release notes. - Projects that already had
"strict": true: nothing changes, apart from any new checks that future versions add to the strict family. - Older projects with no
strictline: upgrading to 6.0 or 7.0 flips you into strict mode overnight and can surface hundreds of errors. Use the rollout plan below rather than turning it off for good.
Every flag that "strict": true enables
The official tsconfig reference lists nine options in the strict family today. Setting strict turns them all on, and you can still switch any single one off by setting it to false next to strict.
| Flag | Added in | What it catches | Typical fix |
|---|---|---|---|
strictNullChecks | 2.0 | Reading or passing values that may be null or undefined | Narrowing, optional chaining, ?? defaults |
noImplicitAny | 1.0 | Parameters and variables that silently become any | Add a type annotation |
strictFunctionTypes | 2.6 | Assigning a function whose parameter types are unsafe for the target signature | Correct the callback or handler signature |
strictBindCallApply | 3.2 | Wrong argument types or counts passed to bind, call and apply | Fix the argument list |
strictPropertyInitialization | 2.7 | Class fields that are declared but never assigned in the constructor | Initialize, assign in the constructor, or mark optional |
noImplicitThis | 2.0 | this used where its type would be any | Arrow function or an explicit this parameter |
alwaysStrict | 2.1 | Parses every file in ECMAScript strict mode and emits "use strict" | Usually nothing; ES modules are already strict |
useUnknownInCatchVariables | 4.4 | Reading properties of a caught error without checking what it is | instanceof Error guard |
strictBuiltinIteratorReturn | 5.6 | Built-in iterator results typed as any instead of undefined | Handle the done case properly |
Two details matter here. First, strictPropertyInitialization only works when strictNullChecks is also on. Second, alwaysStrict can no longer really be switched off: TypeScript 6.0 deprecated alwaysStrict: false and assumes all code is in JavaScript strict mode, and TypeScript 7.0 turned alwaysStrict: false into a hard error. The tsconfig reference also warns that future TypeScript versions may add new checks under strict, so an upgrade can introduce new errors even if you change nothing.
Which strict flags matter most?
In real projects, three flags produce most of the errors and prevent most of the production crashes:
strictNullChecksstops the classic "Cannot read properties of undefined" crash by makingnullandundefinedtheir own types. A value typedUser | undefinedmust be checked before you readuser.email.noImplicitAnycloses the holes where type checking quietly stops. An untyped parameter accepts anything, and every caller loses safety.useUnknownInCatchVariablesreflects the fact that JavaScript can throw anything, including strings andundefined, soerr.messageis not guaranteed to exist.
Related flags worth enabling (not part of strict)
Some of the most useful safety checks are not included in strict. They are stricter still, so enable them once strict itself is clean.
| Flag | Added in | What it does |
|---|---|---|
noUncheckedIndexedAccess | 4.1 | Adds undefined to array index and index signature reads, so items[0] is Item | undefined |
exactOptionalPropertyTypes | 4.4 | Treats theme?: "dark" | "light" as "may be missing" but not "may be set to undefined" |
noImplicitOverride | 4.3 | Requires the override keyword on methods that override a base class, so renames cannot silently break subclasses |
noImplicitReturns | 1.8 | Errors when some code paths in a function do not return a value |
noFallthroughCasesInSwitch | 1.8 | Errors on switch cases that fall through without break or return |
noUncheckedIndexedAccess is the one I add to every new project. It catches the bug strict mode misses most often: assuming an array element or a dictionary key exists.
const sizes = ['S', 'M', 'L']
const first = sizes[0]
const prices: Record<string, number> = {}
const price = prices['sku-123']
With the flag on, both first and price are typed ... | undefined, which is the truth at runtime.
How to enable strict mode in an existing project, step by step
Turning everything on in one commit is fine for a small app. For a codebase with hundreds or thousands of errors, you need a rollout that lets feature work continue while the error count goes down. This is the plan I use on client projects.
- Measure the gap. Run
npx tsc --noEmit --strictonce and save the error count. Run it again per flag (for example--strictNullChecks) to see which flags cost the most. - Pin the current state. If you are upgrading to TypeScript 6 or 7, set
"strict": falseexplicitly so the upgrade itself does not break the build. Upgrade first, fix strictness second. - Enable flags one at a time. Start with the cheap ones (
alwaysStrict,strictBindCallApply,strictFunctionTypes,noImplicitThis), thennoImplicitAny, thenstrictNullChecks, thenstrictPropertyInitializationanduseUnknownInCatchVariables. Better annotations fromnoImplicitAnymake the null checks easier. - Split the big flag by folder.
strictNullChecksusually produces the most errors. Fix one feature or package per pull request so reviews stay small. - Set a
@ts-expect-errorbudget. When a fix is risky, suppress it with// @ts-expect-errorplus a short reason, never@ts-ignore.@ts-expect-errorfails as soon as the error underneath is fixed, so stale suppressions clean themselves up. Count them withgrep -r "@ts-expect-error" src | wc -land only let that number go down. - Gate it in CI. Run
tsc --noEmiton every pull request so no new errors get merged. - Flip the switch. When every individual flag is on, delete them and set
"strict": true.
A mid-migration tsconfig looks like this:
{
"compilerOptions": {
"strict": false,
"noImplicitAny": true,
"strictNullChecks": true,
"useUnknownInCatchVariables": true
}
}
Alternative: migrate file by file with a second tsconfig
If one flag at a time is still too much, create a tsconfig.strict.json that extends your main config, turns strict on and includes only the folders you have already migrated. New code goes into the strict list from day one, and the list grows until it covers the whole project.
{
"extends": "./tsconfig.json",
"compilerOptions": {
"strict": true,
"noEmit": true
},
"include": ["src/lib/**/*", "src/features/checkout/**/*"]
}
Then run both checks in CI. A minimal GitHub Actions job:
name: typecheck
on: [pull_request]
jobs:
tsc:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
- run: npm ci
- run: npx tsc --noEmit
- run: npx tsc --noEmit -p tsconfig.strict.json
Some teams use the community typescript-strict-plugin, which marks unmigrated files with a //@ts-strict-ignore comment. Be careful with it on TypeScript 7.0: the 7.0 release ships without a programmatic API, and a new one is planned for 7.1. Tools that depend on the old compiler API can keep running on TypeScript 6 through the @typescript/typescript6 compatibility package, which installs a separate tsc6 command. The second tsconfig approach has no such dependency.
The 10 most common errors after enabling strict mode
Most strict errors fall into a handful of shapes. Here they are with the error code you will see, why it happens and a before and after fix.
1. 'user' is possibly 'undefined'
Error: TS18048 / TS2532. Comes from strictNullChecks when you read a property of a value that may be missing.
Before:
function greet(user: User | undefined) {
return `Hello, ${user.name}`
}
After:
function greet(user: User | undefined) {
return `Hello, ${user?.name ?? 'there'}`
}
Optional chaining (?.) stops at the first missing value, and ?? supplies a default only for null or undefined, unlike ||, which also replaces 0 and empty strings.
2. Parameter implicitly has an 'any' type
Error: TS7006. Comes from noImplicitAny when TypeScript cannot infer a parameter type.
Before:
function total(items) {
return items.reduce((sum, item) => sum + item.price, 0)
}
After:
type LineItem = { price: number }
function total(items: LineItem[]): number {
return items.reduce((sum, item) => sum + item.price, 0)
}
Annotate parameters at function boundaries. Inside the function, inference usually does the rest.
3. 'err' is of type 'unknown'
Error: TS18046. Comes from useUnknownInCatchVariables, because a thrown value can be anything.
Before:
try {
await saveOrder(order)
} catch (err) {
console.error(err.message)
}
After:
try {
await saveOrder(order)
} catch (err) {
const message = err instanceof Error ? err.message : String(err)
console.error(message)
}
If you log errors in many places, move this check into a small toErrorMessage(err: unknown) helper.
4. Result of .find() is possibly 'undefined'
Error: TS18048. Array.prototype.find returns undefined when nothing matches, and strict mode makes you handle that.
Before:
const user = users.find((u) => u.id === id)
sendEmail(user.email)
After:
const user = users.find((u) => u.id === id)
if (!user) throw new Error(`User ${id} not found`)
sendEmail(user.email)
Throwing early narrows user to User for the rest of the function. Since TypeScript 5.5, simple filter callbacks such as .filter((x) => x !== undefined) also narrow the array type automatically.
5. Type 'string | undefined' is not assignable to type 'string'
Error: TS2322 / TS2345. Very common with environment variables, optional props and URL params.
Before:
const apiUrl: string = process.env.API_URL
After:
const apiUrl = process.env.API_URL
if (!apiUrl) throw new Error('API_URL is not set')
Validate configuration once at startup instead of sprinkling ! across the codebase. For larger configs, a schema library does this in one place.
6. Property has no initializer
Error: TS2564. Comes from strictPropertyInitialization when a class field is declared but never assigned in the constructor.
Before:
class OrderService {
private client: ApiClient
}
After:
class OrderService {
constructor(private client: ApiClient) {}
}
Use the definite assignment assertion (private client!: ApiClient) only when a framework sets the field for you, such as dependency injection or decorators.
7. 'button' is possibly 'null'
Error: TS18047. DOM queries return null when nothing matches, and so does a React useRef before mount.
Before:
const button = document.querySelector('#buy')
button.addEventListener('click', checkout)
After:
const button = document.querySelector<HTMLButtonElement>('#buy')
button?.addEventListener('click', checkout)
If the element must exist, throw a clear error when it is missing instead of silently doing nothing.
8. Element implicitly has an 'any' type because expression of type 'string' can't be used to index
Error: TS7053. Comes from noImplicitAny when you index an object with a plain string.
Before:
const labels = { draft: 'Draft', paid: 'Paid' }
function label(status: string) {
return labels[status]
}
After:
const labels = { draft: 'Draft', paid: 'Paid' } as const
type Status = keyof typeof labels
function label(status: Status) {
return labels[status]
}
Narrow the key to a union of real keys. If the object really is a dictionary, type it as Record<string, string> instead.
9. Binding element implicitly has an 'any' type
Error: TS7031. The React and destructuring version of error 2: untyped props.
Before:
export function Price({ amount, currency }) {
return <span>{amount} {currency}</span>
}
After:
type PriceProps = { amount: number; currency: string }
export function Price({ amount, currency }: PriceProps) {
return <span>{amount} {currency}</span>
}
Define a props type for every component. It doubles as documentation for whoever uses the component next.
10. 'this' implicitly has type 'any'
Error: TS2683. Comes from noImplicitThis in standalone functions that use this.
Before:
function onClick() {
this.classList.toggle('open')
}
After:
function onClick(this: HTMLElement) {
this.classList.toggle('open')
}
A this parameter is erased at compile time. In most modern code, an arrow function or passing the element as a normal argument is even simpler.
One rule covers all ten: the non-null assertion operator (!) is a promise to the compiler, not a fix. Each one switches strict checking off at that spot, so keep them rare, searchable and explained.
Validate external data at the boundary
Strict mode only protects what TypeScript can see. JSON from an API, form input, webhooks and localStorage are all untyped at runtime, whatever your type annotations claim. Parse that data once at the edge of the app with a schema, and the rest of your code can trust its types. I cover this pattern in detail, including shared schemas between client and server, in my guide to type-safe API validation with TypeScript and Zod.
A recommended strict tsconfig for 2026
This is a sensible starting point for a new app bundled with Vite or a similar tool on TypeScript 6 or 7. Adjust module, moduleResolution and types for your runtime.
{
"compilerOptions": {
"target": "es2025",
"module": "esnext",
"moduleResolution": "bundler",
"types": ["node"],
"strict": true,
"noUncheckedIndexedAccess": true,
"exactOptionalPropertyTypes": true,
"noImplicitOverride": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"verbatimModuleSyntax": true,
"isolatedModules": true,
"skipLibCheck": true,
"noEmit": true
},
"include": ["src"]
}
Note the explicit "types": ["node"]. Since TypeScript 6.0 the default for types is an empty array, so global type packages such as @types/node are no longer picked up automatically.
Strict mode in React, Next.js and Node.js
React
The errors you will meet most are untyped props (error 9), refs that are null before mount (error 7) and state that starts empty. Type state that begins empty as useState<User | null>(null) and narrow before rendering. Mark optional props with ? and give them defaults in the destructuring.
Next.js
According to the Next.js TypeScript docs, next build fails when your project has type errors. Since TypeScript 7 has no JavaScript compiler API yet, Next.js uses the project-local tsc CLI by default, so npm install -D typescript@^7 works without extra configuration. The docs also show typescript.tsconfigPath for pointing builds at a separate tsconfig, which is handy during a gradual migration. Avoid typescript.ignoreBuildErrors unless you run tsc --noEmit somewhere else in CI.
Node.js
Node.js can run .ts files directly through type stripping, enabled by default since Node 22.18.0 and 23.6.0. The Node.js TypeScript docs are clear that no type checking is performed: types are replaced with whitespace. Strict mode only helps if you also run tsc --noEmit in your editor and CI. I cover the rest of that workflow in my Node.js 22 features guide.
Keep strict mode from regressing
Once the error count reaches zero, protect it. Strict mode erodes quietly through as any casts and blanket suppressions unless something stops them.
- Type check every pull request with
tsc --noEmitand fail the build on any error. - Lint the escape hatches. The typescript-eslint rules
no-explicit-anyandban-ts-commentcan require a description on every@ts-expect-error, so each exception is visible in review. - Watch the suppression count from step 5 of the rollout and treat any increase as a review comment.
- Re-check after TypeScript upgrades, because new checks can join the strict family.
If you need a team to move a large codebase to TypeScript 7 and strict mode without stalling your roadmap, that is the kind of work I do as part of my custom web development service.
Frequently asked questions
What does "strict": true do in tsconfig?
It enables nine type checks at once: strictNullChecks, noImplicitAny, strictFunctionTypes, strictBindCallApply, strictPropertyInitialization, noImplicitThis, alwaysStrict, useUnknownInCatchVariables and strictBuiltinIteratorReturn. It changes type checking, not your runtime behavior.
Is strict mode enabled by default in TypeScript?
Yes, since TypeScript 6.0, released on March 23, 2026. TypeScript 7.0 kept that default. Before 6.0, strict was off unless you set it, although the tsc --init template in TypeScript 5.9 already wrote "strict": true.
Should I set strict to false after upgrading to TypeScript 6 or 7?
Only as a temporary step. Setting "strict": false explicitly keeps an old project building through the upgrade, but then enable flags one by one, starting with noImplicitAny and strictNullChecks, until you can switch strict back on.
What is the difference between strictNullChecks and noImplicitAny?
strictNullChecks makes null and undefined separate types, so you must handle missing values. noImplicitAny reports places where TypeScript would silently fall back to any, so you must add a type. Both are part of strict, and they are the two flags that produce the most errors in a migration.
Does strict mode make compilation slower?
Not noticeably. The extra analysis is small compared with the compiler itself, and TypeScript 7's native compiler is reported to be 8 to 12 times faster on full builds than TypeScript 6.
Does strict mode change the JavaScript output?
Almost never. The only output effect comes from alwaysStrict, which adds "use strict" to files that are not ES modules. Modules are already strict, so most modern projects emit identical code.
Is noUncheckedIndexedAccess part of strict?
No. noUncheckedIndexedAccess, exactOptionalPropertyTypes and noImplicitOverride are separate flags. They are stricter than strict and well worth enabling once the strict family is clean.
Should I use @ts-ignore or @ts-expect-error during a migration?
Use @ts-expect-error with a short reason. It reports an error when the suppressed problem no longer exists, so unused suppressions get removed instead of hiding new bugs later.
Sources
- TypeScript tsconfig reference: strict
- TypeScript tsconfig reference: noUncheckedIndexedAccess
- TypeScript tsconfig reference: exactOptionalPropertyTypes
- TypeScript tsconfig reference: noImplicitOverride
- Announcing TypeScript 6.0 (Microsoft, March 23, 2026)
- Announcing TypeScript 7.0 (Microsoft, July 8, 2026)
- Announcing TypeScript 7.1 Beta (Microsoft, October 20, 2026)
- TypeScript 5.9 release notes: new tsc --init defaults
- TypeScript 5.5 release notes: inferred type predicates
- typescript package on npm
- Next.js docs: TypeScript
- Node.js docs: Modules: TypeScript
- typescript-eslint: ban-ts-comment