jsconfig.json option

strictNullChecks

  • Default false
  • Since TypeScript 2.0

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

main.js Error confirmed 5.9.3 TypeScript 5.9.3, run 21 October 2026: main.js(8,13): error TS18048: 'price' is possibly 'undefined'. 6.0.3 TypeScript 6.0.3, run 21 October 2026: the same as 5.9.3. main.js(8,13): error TS18048: 'price' is possibly 'undefined'. 7.0.2 TypeScript 7.0.2, run 21 October 2026: the same as 5.9.3. main.js(8,13): error TS18048: 'price' is possibly 'undefined'. checked 21 October 2026
const prices = new Map([
  ["tea", 3],
  ["cake", 4],
]);

const price = prices.get("coffee");
console.log(price.toFixed(2));error TS18048: 'price' is possibly 'undefined'.
strictNullChecks on: Map.get may return undefined.
jsconfig.json for this example
{
  "compilerOptions": {
    "checkJs": true,
    "noEmit": true,
    "strict": true,
    "target": "es2022",
    "module": "nodenext",
    "types": []
  },
  "include": [
    "*.js"
  ]
}
main.js TypeScript 5.9.3 TypeScript 5.9.3, run 21 October 2026: No errors. 6.0.3 TypeScript 6.0.3, run 21 October 2026: the same as 5.9.3. No errors. 7.0.2 TypeScript 7.0.2, run 21 October 2026: the same as 5.9.3. No errors. checked 21 October 2026
const prices = new Map([
  ["tea", 3],
  ["cake", 4],
]);

const price = prices.get("coffee");
console.log(price.toFixed(2));
strictNullChecks off: undefined is ignored, and the code would throw.
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) or if (price) before the use
  • optional chaining, price?.toFixed(2), which gives undefined instead of throwing
  • a fallback with ??: (prices.get("coffee") ?? 0).toFixed(2)
  • instanceof for 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 null is followed, not left any: after let a = null, reading a.length is TS18047 in TypeScript 5.9. Give it a @type when it will hold something else later, so that assignments are checked too.
  • Turning this on in an existing codebase reports many errors at once; noImplicitAny first, then this, is the usual order.

Sources

Last reviewed 20 October 2026.