Without strictNullChecks, null and undefined fit every type, so a value that may be missing looks like it is always there. With it on, they are types of their own: Map.get returns number | undefined, document.querySelector returns Element | null, and using the result without a check is an error (TS18048 for "possibly undefined", TS18047 for "possibly null").
It is part of strict, arrived with TypeScript 2.0, and catches one of the most common runtime errors in JavaScript: reading a property of undefined.
At a glance
| Write | Leave it to strict; write "strictNullChecks": false only to turn this one check back off |
|---|---|
| On the command line | --strictNullChecks |
| Type | boolean |
| Default in TypeScript 5.9 | false (on when strict is on) |
| Default from TypeScript 6.0 | true, through strict (TypeScript 6.0) |
| TypeScript's description | When type checking, take into account 'null' and 'undefined'. |
The description is quoted from TypeScript's own option list (Apache-2.0); see the notices.
Examples
const prices = new Map([
["tea", 3],
["cake", 4],
]);
const price = prices.get("coffee");
console.log(price.toFixed(2));error TS18048: 'price' is possibly 'undefined'.jsconfig.json for this example
{
"compilerOptions": {
"checkJs": true,
"noEmit": true,
"strict": true,
"target": "es2022",
"module": "nodenext",
"types": []
},
"include": [
"*.js"
]
} const prices = new Map([
["tea", 3],
["cake", 4],
]);
const price = prices.get("coffee");
console.log(price.toFixed(2));jsconfig.json for this example
{
"compilerOptions": {
"checkJs": true,
"noEmit": true,
"strict": true,
"target": "es2022",
"module": "nodenext",
"types": [],
"strictNullChecks": false
},
"include": [
"*.js"
]
} Checking before use
Ordinary JavaScript checks are what the checker understands:
if (price !== undefined)orif (price)before the use- optional chaining,
price?.toFixed(2), which givesundefinedinstead of throwing - a fallback with
??:(prices.get("coffee") ?? 0).toFixed(2) instanceoffor DOM lookups:if (el instanceof HTMLInputElement)
There is no ! in JavaScript
TypeScript files can assert "not null" with a postfix !. JavaScript cannot; the alternatives are a check, a fallback, or a cast in JSDoc.
Gotchas
- A variable that starts as
nullis followed, not leftany: afterlet a = null, readinga.lengthis TS18047 in TypeScript 5.9. Give it a@typewhen it will hold something else later, so that assignments are checked too. - Turning this on in an existing codebase reports many errors at once;
noImplicitAnyfirst, then this, is the usual order.
Sources
- TSConfig Reference: strictNullChecks · TypeScript
- TypeScript 2.0 release notes · TypeScript handbook
- Type Checking JavaScript Files · TypeScript handbook
Last reviewed 20 October 2026.