null-or-undefined-check
A strict test for one of null and undefined (x === undefined, x !== null, x === jsonNull) on a value whose declared type holds both (deletedAt?: string | JsonNull, Option<T | JsonNull>, T | null | undefined), in a function that never tests it for the other one. An idiomatic rule: reported only with "safe-ts": { "idiomatic": true } in package.json.
Why: after a migration from null to undefined, undefined often means "not loaded" where null meant "none". A field that can hold both is tested by value (record.deletedAt === undefined), and the other one passes the test: a deleted record reads as not loaded, silently. Convert at the boundary so the value holds only undefined, or test both where both are meant. Guide: Absence.
✕ Rejectednull-or-undefined-check
ts
import type { JsonNull } from "@evobug_com/safe-ts-std/json";
type Issue = { readonly title: string; readonly closedAt?: string | JsonNull };
export function isOpen(issue: Issue): boolean {
return issue.closedAt === undefined;
}✓ Accepted0 diagnostics
ts
import { type JsonNull, jsonNull } from "@evobug_com/safe-ts-std/json";
type Issue = { readonly title: string; readonly closedAt?: string | JsonNull };
export function isOpen(issue: Issue): boolean {
return issue.closedAt === undefined || issue.closedAt === jsonNull;
}The types are read from the declarations, as written: a parameter's or variable's own type, a field of a type declared in the project (here or in another file), and a type alias of such a union. x == null tests both and isn't reported. A test after the other one was ruled out (if (x === undefined) return; if (x === jsonNull) ...) isn't reported either, since the function tests both.