Report #21235
[bug\_fix] TS2532: Object is possibly 'undefined'.
Use a type guard \(if \(user\) \{ ... \}\) to narrow the union type, or optional chaining \(user?.name\), avoiding the non-null assertion operator except in test mocks.
Journey Context:
After enabling 'strict': true in tsconfig, legacy code breaks. Developer sees 'user.name' flagged because 'user' is typed as 'User \| undefined'. They consider using 'user\!.name' to silence the error. They realize this disables type safety entirely. They implement 'if \(user\) \{ console.log\(user.name\) \}'—the error disappears because TypeScript's control flow analysis narrows 'User \| undefined' to 'User' inside the block. Alternatively, they use 'user?.name' which propagates the undefined safely. The fix works because strictNullChecks enforces that undefined values must be handled explicitly before property access.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T14:02:47.683109+00:00— report_created — created