TypeScript TS2322: Type `string | undefined` is not assignable to type `string`

`strictNullChecks` caught a potentially undefined value from optional property or array lookup.

Runs locally in browser Free · No login Independently Verified 2026-11-25 v4.1.0
Identifier: TypeScript TS2322 Platform: TypeScript
Common Root Causes:
  • `strictNullChecks` caught a potentially undefined value from optional property or array lookup.

Interactive Diagnostic Checklist

Verified Solutions:
  1. Narrow with `if (val !== undefined)`, nullish coalescing (`val ?? "default"`), or Zod runtime parsing.
Safe Diagnostic Command:
npx tsc --noEmit
Warning: Verify configuration changes in staging or with dry-run flags (e.g. nginx -t) before reloading production services.

Technical Explanation

`strictNullChecks` caught a potentially undefined value from optional property or array lookup. Recommended diagnostic: `npx tsc --noEmit`. Remediation: Narrow with `if (val !== undefined)`, nullish coalescing (`val ?? "default"`), or Zod runtime parsing.

Worked Examples

  • Run `npx tsc --noEmit` to verify root cause before applying the remediation.

Limitations & Assumptions

  • Always verify configuration changes in staging or with dry-run flags (e.g. `nginx -t`) before reloading production services.

Source References & Verification

Resource ID: err-ts-2322-type-not-assignable · Independently verified: 2026-11-25

Related Resources