# TypeScript strict mode enabled

- **Pattern:** `ab-002135` (`code-quality-essentials.type-safety.strict-mode`)
- **Severity:** critical
- **Lifecycle:** active
- **Last modified:** 2026-04-20
- **Canonical URL:** https://auditbuffet.com/patterns/ab-002135
- **License:** CC-BY-4.0 — attribute to AuditBuffet Pattern Catalog (https://auditbuffet.com/patterns/ab-002135)

## Why it matters

Without TypeScript strict mode, the compiler silently allows implicit `any` types, skips null-safety checks, and misses a family of type errors that only surface at runtime. ISO 25010:2011 §6.5.4 classifies these as reliability defects. A single `null` dereference in an authentication path or payment flow can take down production. Strict mode is the umbrella flag — disabling it means `noImplicitAny`, `strictNullChecks`, and `strictFunctionTypes` are all off simultaneously.

## Severity rationale

Critical because disabling strict mode silently opts out of the compiler's entire null-safety and implicit-any detection family, letting whole classes of runtime crashes ship undetected.

## Remediation

Enable strict mode in `tsconfig.json`. Do not compensate by disabling individual sub-flags — that defeats the flag's purpose. To migrate an existing codebase without a full-stop build failure, temporarily set `"noEmitOnError": false` while you work through the errors one file at a time.

```json
{
  "compilerOptions": {
    "strict": true,
    "noUncheckedIndexedAccess": true
  }
}
```

Use `// @ts-expect-error` (with a comment) to suppress individual stubborn errors during migration — never `// @ts-ignore` without context.

## Detection

- **ID:** `strict-mode`
- **Severity:** `critical`
- **What to look for:** Open `tsconfig.json` and read `compilerOptions`. Look for `"strict": true`. The `strict` flag is a convenience flag that enables a family of strict type checking options simultaneously: `noImplicitAny`, `strictNullChecks`, `strictFunctionTypes`, `strictBindCallApply`, `strictPropertyInitialization`, `noImplicitThis`, and `alwaysStrict`. If `strict` is absent or false, check whether these sub-flags are individually enabled (partial credit scenario: note which are missing). A `strict: true` setting that is then partially overridden by explicit `"noImplicitAny": false` still fails this check.
- **Detector snippet (shell-capable tools only):** If `jq` is available, read the explicit `compilerOptions.strict` value. Output `"true"` means pass. Output `"false"` or `"null"`, or exit >=2 (file not found / malformed JSON), means the snippet is inconclusive — fall back to the prose reasoning below and walk any `extends:` chain manually.

  ```detect-jq
  jq -r '.compilerOptions.strict // "null"' tsconfig.json
  ```

- **Pass criteria:** Quote the actual `strict` value from `tsconfig.json`. On pass, report the count of strict-related compiler options enabled. Count all `tsconfig.json` files. `compilerOptions.strict` is `true` and is not overridden by explicit disabling of individual sub-flags with at least 1 verified location.
- **Fail criteria:** `strict` is `false`, missing, or `strict: true` is paired with explicit `false` overrides on sub-flags. A project that relies only on individual strict flags without the umbrella `strict: true` does not count as pass.
- **Skip (N/A) when:** Project has no TypeScript files — all source files are `.js` or `.jsx` with no `tsconfig.json`.
- **Detail on fail:** `"tsconfig.json has strict: false (or missing); noImplicitAny and strictNullChecks are not enforced"` (max 500 chars)
- **Cross-reference:** Compare with `code-quality-essentials.type-safety.strict-null-checks` — strict mode enables strictNullChecks, but this check verifies the umbrella flag.
- **Remediation:** Enable strict mode in `tsconfig.json`. If the project has existing code that does not compile under strict mode, enable it progressively using `// @ts-expect-error` on specific lines while you fix each class of issue. Never disable a sub-flag to silence the migration — that defeats the purpose.

  ```json
  {
    "compilerOptions": {
      "strict": true,
      "noUncheckedIndexedAccess": true
    }
  }
  ```

  To see what errors strict mode surfaces without failing your build, temporarily add `"noEmitOnError": false` during migration.

## External references

- iso-25010 maintainability.modifiability

Taxons: code-quality

HTML version: https://auditbuffet.com/patterns/ab-002135
