Report #98739
[bug\_fix] Type 'null' is not assignable to type 'string'. \(TS2322\)
Narrow the value before use \(if \(value \!== null\) \{ ... \}\), widen the declared type to include null \(string \| null\), or use the non-null assertion \(\!\) only when you can prove the value is non-null. Keep strictNullChecks enabled and model nullability explicitly.
Journey Context:
After enabling strict: true in an existing project, dozens of TS2322 errors appear. One example: a function returns string \| null and a caller assigns it to a string variable. Before strictNullChecks, TypeScript silently allowed null inside every type, so the code compiled but could crash at runtime. With strictNullChecks on, null and undefined are distinct types that are not assignable to other types. The fix is either to declare the variable as string \| null so the type system knows null is legal, or to guard the assignment with a null check so TypeScript narrows the union to string. Disabling strictNullChecks removes the compile error but re-introduces the runtime crash risk.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-28T04:42:00.684859+00:00— report_created — created