1{ "compilerOptions": {2 "target": "es2022",3 "strict": false "strict": true4} }strict checks0 on9 onnoImplicitAnystrictNullChecksstrictFunctionTypesstrictBindCallApplystrictPropertyInitializationstrictBuiltinIteratorReturnnoImplicitThisuseUnknownInCatchVariablesalwaysStricttsctype checker!✓1const names = ["Ada", "Lin"];2const who = names.find(n => n === "Bo");3function shout(s) {function shout(s: string) {4 return s.toUpperCase();5}6console.log(shout(who));console.log(shout(who ?? "nobody"));$ node app.jsTypeErrorreading 'toUpperCase'NOBODYTSstrictundefined"nobody"
Back row: tsconfig.json, the 9 strict checks, and tscFront row: app.ts and the laptop that runs itTokens: the file going to tsc, the strict switch, and the values undefined and "nobody"At the back: tsconfig.json with its one strict switch, the panel of the 9 checks it turns on, and tsc. In front: app.ts and a laptop running it with Node.js. With strict off, tsc passes the code and it crashes at run time with a TypeError. With strict on, noImplicitAny and strictNullChecks point at lines 3 and 6; after the fixes it prints NOBODY. The error texts are exactly what tsc 5.9 prints for these files. By default tsc still writes app.js even when it reports errors (noEmitOnError is off).

The hidden bug

  1. With "strict": false, tsc checks app.ts and reports zero errors. But look closer: find gives undefined when no name matches, and s on line 3 has no type, so nothing about s is checked.

One switch

What it catches

In practice

What happens

;; step 1/9 · loose
tsconfig.json: "strict": false
$ tsc -p .
(no errors)

  1  const names = ["Ada", "Lin"];
> 2  const who = names.find(n => n === "Bo");
> 3  function shout(s) {
  4      return s.toUpperCase();
  5  }
  6  console.log(shout(who));

The list of nine is TypeScript 5.9's. New TypeScript versions sometimes add a check to the strict family, so upgrading can show new errors in strict projects. Strict mode only changes the checking, with one small exception: alwaysStrict makes tsc put "use strict"; at the top of each JavaScript file it writes.