Report #71236
[bug\_fix] Type 'string \| undefined' is not assignable to type 'string'
Use a type guard to narrow the type: \`if \(user\) \{ /\* user is string here \*/ \}\`, or provide a default value using nullish coalescing: \`const name = user ?? 'Anonymous'\`, or use the non-null assertion operator \`user\!\` only when you are certain the value is defined.
Journey Context:
You fetch data from an API: \`const user = await fetchUser\(\)\` which returns \`Promise\`. You try to render \`user.name\` in React. TypeScript throws "Type 'string \| undefined' is not assignable to type 'string'". You try \`user?.name\` which satisfies the compiler for reading, but later you need to pass \`user\` to a function \`processUser\(user: User\)\`. You try to force it with \`as User\` but worry about runtime crashes. You realize \`strictNullChecks\` forces you to handle the undefined case explicitly. You write \`if \(\!user\) throw new Error\('Not found'\)\` and after that check, TypeScript narrows the type to just \`User\`.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T02:08:38.334449+00:00— report_created — created