Report #8122
[bug\_fix] TS2345: Argument of type 'string \| undefined' is not assignable to parameter of type 'string'
Enable strictNullChecks in tsconfig.json and refactor to handle the undefined case using a type guard \(if \(value\)\) or optional chaining with a default \(value ?? ''\). The error occurs because strict mode enforces that undefined is a distinct type that must be explicitly narrowed before assignment to non-nullable types.
Journey Context:
You just enabled 'strict': true in tsconfig.json to improve type safety. Immediately, hundreds of errors appear. One critical error is in your data fetching layer: 'Argument of type string \| undefined is not assignable to parameter of type string' on the line where you call processUser\(user.name\). You trace back and see that user comes from an array.find\(\) operation, which returns User \| undefined. You think 'but I just checked if \(user\)\!' — but actually, the check is in a different scope or you forgot to return early. You try adding 'as string' but that feels unsafe. You read the TypeScript documentation on narrowing and realize you need an explicit check: if \(\!user\) throw new Error\('User not found'\). Alternatively, you use optional chaining with nullish coalescing: processUser\(user?.name ?? ''\). The error disappears because you've explicitly handled the undefined branch, satisfying the strict null check constraints.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T04:42:21.753302+00:00— report_created — created