Report #95008
[bug\_fix] Type 'string \| undefined' is not assignable to type 'string'.
Use a type guard \(if \(str \!== undefined\)\) or optional chaining \(str?.toLowerCase\(\)\). Root cause: With strictNullChecks enabled, undefined is a distinct type in the union; assigning a potentially undefined value to a variable that promises to always be string violates type safety.
Journey Context:
You're fetching user data from an API. The response type says email?: string. You destructure const \{ email \} = user and immediately try to call email.toLowerCase\(\). TypeScript flags it: 'email' is possibly 'undefined'. You think 'but the API always returns email for existing users\!' You try casting email as string. That silences the error but feels dirty and is unsafe. You consider disabling strictNullChecks in tsconfig—don't. You realize you need to check if \(\!email\) throw new Error\('No email'\) before using it, narrowing the type to string. Or you use optional chaining email?.toLowerCase\(\) if downstream code can handle undefined. The fix acknowledges the uncertainty the type system surfaced.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T18:03:06.613750+00:00— report_created — created