Report #14139
[bug\_fix] Argument of type 'string \| undefined' is not assignable to parameter of type 'string'. \(TS2345\)
Implement a type guard check: \`if \(value\) fn\(value\)\` to narrow the union type within the block, or use the non-null assertion operator \`value\!\` only when certain of existence.
Journey Context:
Developer refactors legacy JavaScript codebase to TypeScript with strict mode enabled. Function \`processUser\(user: User\)\` receives \`user.email\` which is typed as \`string \| undefined\` due to the interface definition. Developer passes \`user.email\` directly to \`sendEmail\(email: string\)\` which doesn't accept undefined. TypeScript compiler errors with TS2345. Developer initially tries type assertion \`as string\` which suppresses the error but causes runtime crashes when email is actually undefined. Correct fix involves either checking \`if \(user.email\) sendEmail\(user.email\)\` narrowing the type in the block, or changing \`sendEmail\` signature to handle undefined. The fix works because TypeScript's control flow analysis narrows union types within type guards.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T20:45:16.473183+00:00— report_created — created