Skip to content

typescript.missing_null_check

Correctness High

Detects potential null/undefined access without proper checks.

Missing null checks:

  • Runtime crashes — “Cannot read property of undefined”
  • Silent failures — Undefined propagates through code
  • User-facing errors — Unhandled exceptions break UX
// ❌ 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';
}
  • Property access on nullable types
  • Missing null guards before access
  • Unsafe type assertions

Unfault can add optional chaining or null checks.