Q22 of 38 · TypeScript

What does `strict: true` enable in `tsconfig.json`, and which flags matter most for test projects?

TypeScriptMidtypescriptstrict-modetsconfigstrictNullChecksnoImplicitAny

Short answer

Short answer: `strict: true` enables a group of strict type-checking flags: `strictNullChecks`, `strictFunctionTypes`, `strictPropertyInitialization`, `noImplicitAny`, `noImplicitThis`, and others. For test projects, `strictNullChecks` and `noImplicitAny` deliver the most value by eliminating silent null bugs and untyped code.

Detail

"strict": true in tsconfig is a shorthand that enables a collection of strictness flags together. Knowing what each does helps you understand what errors you'll see and why they exist.

Key flags included in strict:

  • strictNullChecks: null and undefined are not assignable to other types. Prevents a huge class of null-dereference bugs.
  • noImplicitAny: Variables and parameters without a type annotation are not silently typed as any. Forces you to be explicit.
  • strictFunctionTypes: Function parameter types are checked contravariantly. Prevents subtle callback type errors.
  • strictPropertyInitialization: Class properties must be initialized in the constructor or declared with definite assignment assertion (!).
  • noImplicitThis: Disallows this with an implied any type.
  • useUnknownInCatchVariables: Catch bindings are typed as unknown rather than any.

For test projects: Start with strict enabled from day one — retrofitting it onto an existing suite means touching every file. If you're migrating, use // @ts-strict-ignore per file and ratchet in.

Additional useful flags (not in strict but recommended):

  • noUnusedLocals / noUnusedParameters: catch stale test variables
  • exactOptionalPropertyTypes: distinguish undefined from "property absent"
  • noUncheckedIndexedAccess: array indexing returns T | undefined

// EXAMPLE

// tsconfig.json for a Playwright test project
{
  "compilerOptions": {
    "target": "ES2022",
    "module": "commonjs",
    "strict": true,                        // all strict flags
    "noUnusedLocals": true,                // catch dead variables
    "noUnusedParameters": true,            // catch unused params
    "exactOptionalPropertyTypes": true,    // stricter optional props
    "noUncheckedIndexedAccess": true,      // arr[0] is T | undefined
    "moduleResolution": "bundler",
    "esModuleInterop": true,
    "skipLibCheck": true,                  // don't check node_modules types
    "baseUrl": ".",
    "paths": { "@/*": ["./src/*"] }
  },
  "include": ["tests/**/*.ts", "fixtures/**/*.ts"]
}

// WHAT INTERVIEWERS LOOK FOR

Knowing what `strict: true` expands to and which flags matter most. Recommending strict from day one on new projects. The `noUncheckedIndexedAccess` flag for array safety is a senior bonus. Connecting these flags to real bugs they prevent.

// COMMON PITFALL

Adding `skipLibCheck: true` for the wrong reasons — it skips type checking in node_modules .d.ts files, which is usually fine for performance, but it also skips your own `.d.ts` files if you have type-only re-export files.