Report #101952
[bug\_fix] Object is possibly 'undefined'. TS2532 / TS2533
Use a type guard, optional chaining, or nullish coalescing to handle the undefined case before accessing the property. Avoid \`\!\` unless you have an invariant proving the value is set.
Journey Context:
A fetch wrapper returned a response typed as \`User \| undefined\`. A downstream line did \`user.email.toLowerCase\(\)\` and \`tsc\` flagged \`user.email\` with TS2532 because \`user\` itself could be undefined. The first reaction was to add \`\!\` everywhere to silence the compiler, but that caused a runtime crash in CI when an API returned 204 with no body. The proper fix was to add a guard: \`if \(\!user\) throw new Error\('User not found'\);\` before accessing the property. In simpler rendering cases, \`user?.email?.toLowerCase\(\) ?? ''\` kept the code flat and safe. The deeper root cause was that the API client was typed as returning a union but the consumers were written as if the data was always present.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-07-08T04:43:26.644065+00:00— report_created — created