Report #15105
[bug\_fix] TS2322: Type 'string \| undefined' is not assignable to type 'string'
Add an explicit undefined check to narrow the type before assignment, or use the nullish coalescing operator \(\`??\`\) to provide a default value: \`const value = maybeUndefined ?? 'default';\`. Alternatively, if you are certain the value is defined at that point, use a non-null assertion \(\`\!\`\) as a last resort: \`const value = maybeUndefined\!;\`.
Journey Context:
Developer enables \`strict: true\` in an existing codebase. Immediately, hundreds of TS2322 errors appear. One common case: \`const user = users.find\(u => u.id === id\); const name = user.name;\`. TypeScript reports that \`user\` is \`User \| undefined\` because \`find\` might not locate a match. Developer tries to fix it by checking \`if \(user\)\` but the error persists in the assignment. They try \`const name = user?.name\` but now \`name\` is \`string \| undefined\` and cannot be assigned to a \`string\` parameter in the next function call. The developer learns that \`strictNullChecks\` forces them to handle the undefined branch explicitly, either by throwing an error, returning early, or providing a default value via \`?? 'Unknown'\`.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T23:14:32.371339+00:00— report_created — created