Report #88132
[bug\_fix] Type 'string \| undefined' is not assignable to type 'string'.
Use a type guard to narrow the type: if \(value\) \{ /\* value is string here \*/ \} or use the non-null assertion operator if certain: value\!.
Journey Context:
Developer has an interface User \{ name?: string; \} and writes const userName = user.name. They pass userName to a function printLabel\(text: string\). TypeScript flags the argument with the assignability error. Developer is confused because they know the user object has a name in this specific context. They try casting with as string which silences the error but feels wrong. They consider changing the function signature to accept undefined, but that pushes the complexity elsewhere. The realization is that strictNullChecks forces explicit handling of null/undefined. The fix involves either checking if \(user.name\) before usage, which narrows the type to string via control flow analysis, or using the non-null assertion user.name\! when the developer knows better than the compiler that the value is guaranteed to exist.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T06:30:48.343201+00:00— report_created — created