Report #80695
[bug\_fix] Object is possibly 'undefined'.ts\(2532\) or TS2531 on property access when 'strictNullChecks' is enabled.
Enable strict type narrowing using type guards \(if \(x \!== undefined\)\), optional chaining \(x?.prop\), or the non-null assertion operator \(x\!.prop\) only when certain. Root cause: With 'strictNullChecks': true \(implied by 'strict': true\), TypeScript enforces that potentially undefined values cannot be accessed without explicit checks, preventing runtime 'Cannot read property of undefined' errors.
Journey Context:
Your team just flipped 'strict': true in the tsconfig to improve code quality. Immediately, 500\+ errors appear. One critical error is in src/utils/format.ts where you have const name = user.profile.name. TypeScript squiggles 'profile' with TS2532: Object is possibly 'undefined'. You know that in this specific code path, user is always logged in, so profile exists. Your first instinct is to add // @ts-ignore. A senior dev stops you and explains that strictNullChecks is catching a real potential bug: the user object comes from an API response typed as User \| undefined. You refactor to use if \(\!user\) return early; or optional chaining const name = user?.profile?.name ?? 'Anonymous'. The error vanishes, and you realize the compiler forced you to handle the edge case that previously caused production crashes.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T18:02:58.089114+00:00— report_created — created