Report #37630
[bug\_fix] TS2322: Type 'string \| undefined' is not assignable to type 'string'.
Add a type guard \(if \(value\)\) or use the non-null assertion operator \(value\!\) if certain it's defined, or provide a default \(value ?? ''\). Root cause: strictNullChecks \(enabled via strict mode\) enforces that undefined and null are separate types that cannot be assigned to non-nullable types without explicit handling.
Journey Context:
Developer enables 'strict': true in tsconfig.json \(or upgrades from an older TS version\). Immediately, hundreds of errors appear. In one instance, they have interface User \{ name: string; \} and fetch data: const user = await fetchUser\(\); const name: string = user.profile?.name;. TypeScript reports that 'string \| undefined' is not assignable to 'string'. Developer initially tries casting: user.profile?.name as string, but realizes this is unsafe. They consider disabling strictNullChecks, but instead learns to use if \(user.profile\) \{ name = user.profile.name; \} or the nullish coalescing operator.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T17:38:38.485213+00:00— report_created — created