typescript.missing_null_check
Correctness
High
Detects potential null/undefined access without proper checks.
Why It Matters
Section titled “Why It Matters”Missing null checks:
- Runtime crashes — “Cannot read property of undefined”
- Silent failures — Undefined propagates through code
- User-facing errors — Unhandled exceptions break UX
Example
Section titled “Example”// ❌ Before (no null check)function getUserName(user: User | null): string { return user.name; // Crashes if user is null!}// ✅ After (with null check)function getUserName(user: User | null): string { if (!user) { throw new Error('User is required'); } return user.name;}
// Or with optional chaining:function getUserName(user: User | null): string | undefined { return user?.name;}
// Or with nullish coalescing:function getUserName(user: User | null): string { return user?.name ?? 'Anonymous';}What Unfault Detects
Section titled “What Unfault Detects”- Property access on nullable types
- Missing null guards before access
- Unsafe type assertions
Auto-Fix
Section titled “Auto-Fix”Unfault can add optional chaining or null checks.