Skip to content

prefer-nullish-default ​

enabled || true, limit || 10: a default given with || where ?? was meant.

Why: || replaces every falsy value, so options.enabled || true is always true, and limit || 10 turns a deliberate 0 into 10. ?? only replaces undefined (and null, which SAFE-TS code doesn't have) (v8.dev).

ts
import type { Option } from "@evobug_com/safe-ts-std/result";

export function pageSize(requested: Option<number>): number {
  return requested || 20;
}
✓ Accepted0 diagnostics
ts
import type { Option } from "@evobug_com/safe-ts-std/result";

export function pageSize(requested: Option<number>): number {
  return requested ?? 20;
}

Quick fix: Use ??. Only boolean true and non-zero numbers as defaults are reported: label || "none" usually means to replace an empty string too.

Not reported: a left side that can't be undefined, where replacing 0, NaN or "" is the point: arithmetic, Math.*(...), Number(...), parseInt/parseFloat, .length, literals, a const holding one of these, and a call to a function declared to return a type without undefined ((...): number), in this file or imported. There ?? would never apply: the quick fix would drop the default, not keep the 0. A function declared to return Option<number> is still reported.

✅ Accepted: 0 must not divide, and a timeout of 0 means "not set"

✓ Accepted0 diagnostics
ts
export function direction(dx: number, dy: number): readonly [number, number] {
  const length = Math.hypot(dx, dy) || 1;
  return [dx / length, dy / length];
}

function configuredSeconds(value: unknown): number {
  return typeof value === "number" && Number.isFinite(value) ? value : 0;
}

export function timeoutSeconds(setting: unknown): number {
  return configuredSeconds(setting) || 30;
}

el.getAttribute(name) || 1 isn't reported either. getAttribute returns string | null, and an empty attribute (data-size="") means "not set" as much as a missing one: with ??, Number("") would give 0.

MIT OR Apache-2.0 · Docs by Gemini 4 Neon Extra