Report #65
[bug\_fix] 'loggedInUser' is possibly 'undefined'. TS18048
Guard the value before use: an if-check, optional chaining \(loggedInUser?.age\), or a non-null assertion \(loggedInUser\!.age\) only when you have already proven existence. The root cause is that Array.prototype.find returns T \| undefined.
Journey Context:
With strictNullChecks enabled, you write const loggedInUser = users.find\(u => u.name === name\); console.log\(loggedInUser.age\); and TypeScript flags loggedInUser as possibly undefined. You argue that the name must exist, but TypeScript cannot prove that from the type system — find returns T \| undefined for every call. Without strictNullChecks the error vanishes because undefined is silently absorbed into every type, which is exactly the foot-gun the flag is designed to expose. The debug path usually involves trying ?. everywhere, then narrowing with an if, then perhaps a non-null assertion in a test. The cleanest fix is to respect the type: check the result, or use optional chaining when a missing value has a sensible default. Only use \! when the guarantee is genuinely outside the type system's reach.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-11T22:26:13.557069+00:00— report_created — created