Skip to content

Absence: undefined, not null ​

JavaScript splits "nothing" across null and undefined, so code routinely checks for one, receives the other, and crashes on .length of null. SAFE-TS standardizes on undefined everywhere.

In short

  • Use undefined, never null. Option<T> is a clear alias for T | undefined with zero runtime cost.
  • Lean on built-in operators: ?., ??, and default parameters all speak undefined.
  • Convert at the boundary: normalize null from APIs and databases into undefined on arrival, then check Option<T> only against undefined.
  • Explicit wire null: JSON.stringify omits undefined keys—emit null at serialization boundaries only when a protocol requires it (on the wire; for HTTP/WS clients, see where to look).
  • Distinct absences get distinct names: don't use jsonNull to mean two different things in app state (why).

Use undefined for a missing value ​

✕ Rejectedno-null
ts
export type User = { readonly name: string; readonly email: string | null };

export function findUser(users: readonly User[], name: string): User | null {
  return users.find((user) => user.name === name) ?? null;
}
✓ Accepted0 diagnostics
ts
import type { Option } from "@evobug_com/safe-ts-std/result";

export type User = { readonly name: string; readonly email: Option<string> };

export function findUser(users: readonly User[], name: string): Option<User> {
  return users.find((user) => user.name === name);
}

export function contactLine(user: User): string {
  return user.email === undefined ? user.name : `${user.name} <${user.email}>`;
}

Option<string> is just string | undefined, so it costs nothing at runtime. TypeScript makes the caller handle the missing case before using the value.

?., ?? and default parameters all work with undefined:

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

type Profile = { readonly address: Option<{ readonly city: Option<string> }> };

export function city(profile: Profile): string {
  return profile.address?.city ?? "unknown";
}

export function greeting(name: Option<string>, punctuation = "!"): string {
  return `Hello ${name ?? "stranger"}${punctuation}`;
}

Optional fields: ?: or Option<T>? ​

  • field?: T means the caller may leave it out.
  • field: Option<T> means it's always there, but may be undefined.

The difference is only enforced with exactOptionalPropertyTypes in your tsconfig, which is recommended. With it, kind?: Size refuses an explicit undefined, so { name, kind: kind === "custom" ? undefined : kind } doesn't compile. Leave the key out (below: a conditional spread, or two objects), or declare kind: Option<Size> if the key is always there.

Dropping an optional key ​

With exactOptionalPropertyTypes, { ...settings, theme: undefined } doesn't compile for theme?: Theme, and delete copy.theme changes the object behind other code's back. Drop the key with omit (from @evobug_com/safe-ts-std/dict), which copies the rest: omit(settings, "theme", "fontSize") is an Omit<Settings, "theme" | "fontSize">.

✓ Accepted0 diagnostics
ts
import { omit } from "@evobug_com/safe-ts-std/dict";

type Settings = { readonly volume: number; readonly theme?: "light" | "dark"; readonly fontSize?: number };

export function resetLooks(settings: Settings): Settings {
  return omit(settings, "theme", "fontSize");
}

With it, a ?: field can't be set to undefined, so code written without it stops compiling where it fills an optional field from a condition: { id, delivery: delivery === "pickup" ? undefined : delivery } is refused for delivery?: .... Leave the key out instead. The recommended form is a conditional spread of a one-key literal, ...(x === undefined ? {} : { x }), also inside a nested object or an argument:

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

type Callbacks = { readonly onAccept?: () => void; readonly onCancel?: () => void };

declare function openDialog(options: { readonly title: string; readonly callbacks: Callbacks }): void;

export function confirm(title: string, onAccept: Option<() => void>, onCancel: Option<() => void>): void {
  openDialog({
    title,
    callbacks: {
      ...(onAccept === undefined ? {} : { onAccept }),
      ...(onCancel === undefined ? {} : { onCancel }),
    },
  });
}

stable-shape accepts one such spread in any literal, and two where the type the literal is written for declares both keys optional (here Callbacks, found through the argument's field). Three or more make eight shapes or more: there, and for objects read in a hot loop, declare the fields Option<T> (x?: T | undefined) and always write them, x: undefined included. The same goes for a Vue component's optional props, which a template always passes (:x="maybe"): declare them x?: Option<T>.

Or choose between two object literals, one without the key:

✓ Accepted0 diagnostics
ts
type Delivery = "pickup" | "courier" | "post";

export type Order = { readonly id: string; readonly delivery?: Exclude<Delivery, "pickup"> };

export function order(id: string, delivery: Delivery): Order {
  return delivery === "pickup" ? { id } : { id, delivery };
}

If the field is always written and undefined is a real value, declare it Option<T> instead.

With the idiomatic rules on, no-optional-field asks for Option<T> in the project's own types: a value whose type doesn't list an optional key is assignable to the type, and may hold anything under that key (a type it passed through allowed extra properties). ?: stays for JSON payloads, props and a library's options, which the rule leaves alone.

items[i] may be missing ​

By default TypeScript types items[i] as if every index existed. With noUncheckedIndexedAccess in your tsconfig it becomes T | undefined, and TypeScript makes you handle it. safe-ts check warns when that setting is off.

✓ Accepted0 diagnostics
ts
export function greeting(names: readonly string[]): string {
  const [first] = names;
  return first === undefined ? "Hello" : `Hello ${first}`;
}

Where the code checks the bound itself, bytes[i]! is allowed: in for (let i = 0; i < bytes.length; i++), also over cart.lines, descending, items[i + 1]! under i + 1 < items.length, after if (i >= items.length) return;, and the other shapes no-unchecked-cast lists, as long as nothing changes the array or the index in between. bytes[i] ?? 0 works in any loop, and costs nothing measurable. Don't switch a typed array's index loop to for...of to avoid the undefined: over a Uint8Array that is several times slower (Performance myths).

null from outside ​

APIs, databases and JSON.parse give you null. Turn it into undefined where the data comes in, and the rest of your code never sees it. parseJson<T> does it for you. When you check a value by hand, value != undefined (with !=, not !==) is false for both null and undefined:

✓ Accepted0 diagnostics
ts
export function isPresent(value: unknown): boolean {
  return value != undefined;
}

Comparisons are where a bulk rewrite from null to undefined goes wrong, in both directions:

  • getItem returns string | null, so localStorage.getItem(key) !== undefined is always true, and TypeScript accepts the comparison without a word. no-undefined-check-for-null reports such checks. Compare with null (getItem(key) !== null, what that API returns), or turn the value into an Option where it comes in.
  • A value that is now an Option is never null, so code still testing for it is wrong: next === null never stops a loop, assert.equal(next, null) always fails and expect(next).not.toBeNull() always passes. no-null-check-for-undefined reports these where the type has no null (an Option, a ?: field, across files), and leaves alone what may hold one: a DOM lookup keeps its toBeNull().

❌ Rejected: undefined is never null

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

type Cart = { readonly coupon: Option<string> };

export function hasCoupon(cart: Cart): boolean {
  return cart.coupon !== null;
}

The feature packs' safe versions do that for you. With the browser pack, querySelector(document, sel) returns an Option<Element>, and so do closest(el, sel), getAttribute(el, name), get(params, key) and urlParse(text): undefined where the original gives null, and any other value ("", 0) as it is. Comparing with undefined is then right, and comparing with null is the bug (no-null-check-for-undefined reports it). A member that also fails returns a Result of an Option: the browser's getItem(localStorage, key) is a Result<Option<string>, E>, because reading storage throws where the browser denies it or the store is damaged.

✓ Accepted0 diagnostics
ts
import { getItem } from "@evobug_com/safe-ts-feature-browser/storage";
import { closest, querySelector } from "@evobug_com/safe-ts-feature-browser/dom";
import { q, type Option, type Result } from "@evobug_com/safe-ts-std/result";

export function savedCart(): Result<Option<string>, unknown> {
  const cart = q(getItem(localStorage, "cart"));
  return cart;
}

export function hasCoupon(): boolean {
  return querySelector(document, "input[name=coupon]") !== undefined;
}

export function orderForm(button: Element): Option<HTMLFormElement> {
  return closest(button, "form");
}
ts
import { getItem } from "@evobug_com/safe-ts-feature-browser/storage";
import { closest, querySelector } from "@evobug_com/safe-ts-feature-browser/dom";
import { Err as __qErr } from "@evobug_com/safe-ts-std/result"; import { q, type Option, type Result } from "@evobug_com/safe-ts-std/result";

export function savedCart(): Result<Option<string>, unknown> {
  const __q1 = getItem(localStorage, "cart"); if (__q1 instanceof __qErr) return __q1; const cart = __q1;
  return cart;
}

export function hasCoupon(): boolean {
  return querySelector(document, "input[name=coupon]") !== undefined;
}

export function orderForm(button: Element): Option<HTMLFormElement> {
  return closest(button, "form");
}

A safe version also takes undefined where the original wants a null: insertBefore(list, item, undefined) appends, as list.insertBefore(item, null) does.

Going the other way, some outside code needs a null: Object.create(null), a JSON body whose protocol asks for an explicit null, button.onclick = null. no-null doesn't report a null written as an argument of a global or package call (also inside an object literal written there), set on an event handler property, or tested with === null. Nor one (also as value ?? null or a branch of ?:) given where a package's or the platform's type is expected:

  • returned from a function declared to return one (function bound(v): SQLInputValue), also an arrow (params.map((p): SQLInputValue => p ?? null));
  • pushed into, or written in, an array declared with such elements (const params: SQLInputValue[]), or a variable declared with such a type;
  • assigned to a field of a package's object (group.parent = null with group: Group, also for each child of group.children);
  • passed to a method of a value declared with the platform's type (gl.texImage2D(..., null) with gl: WebGL2RenderingContext);
  • in the type of a parameter el: HTMLElement | null that only hands the value on to outside code or tests it (a test helper taking querySelector's value), without returning or storing it.

Inside your own code it is still undefined.

A database is both directions at once. Node's SQLite gives a null for SQL NULL, and refuses undefined as a parameter. There the null is a value, not absence, so the safe versions (get(statement)) leave rows as they are. Read rows through validate<T>, which turns the null of an optional field into undefined, and write ?? null in the parameters. A call on a value declared with a package's type (#insert: StatementSync) goes outside the project, so no-null allows that null:

✓ Accepted0 diagnostics
ts
import type { DatabaseSync, StatementSync } from "node:sqlite";
import { type JsonResult, validate } from "@evobug_com/safe-ts-std/json";
import type { Option } from "@evobug_com/safe-ts-std/result";

type Account = { readonly id: number; readonly name: string; readonly note?: string };

export class Accounts {
  readonly #insert: StatementSync;
  readonly #byId: StatementSync;
  constructor(db: DatabaseSync) {
    this.#insert = db.prepare("INSERT INTO accounts (name, note) VALUES (:name, :note)");
    this.#byId = db.prepare("SELECT id, name, note FROM accounts WHERE id = :id");
  }
  add(name: string, note: Option<string>): void {
    this.#insert.run({ name, note: note ?? null });
  }
  // No such row is `undefined`; a row that doesn't fit `Account` is an error.
  find(id: number): JsonResult<Option<Account>> {
    const row = this.#byId.get({ id });
    return row === undefined ? undefined : validate<Account>(row);
  }
}
ts
import type { DatabaseSync, StatementSync } from "node:sqlite";
import { parseJsonWith as __jsonParse, validateWith as __jsonValidate, jsonFail as __jsonFail, isJsonErr as __jsonIsErr, isJsonObject as __jsonIsObject, type JsonResult as __JsonResult } from "@evobug_com/safe-ts-std/json"; import { type JsonResult, validate } from "@evobug_com/safe-ts-std/json";
import type { Option } from "@evobug_com/safe-ts-std/result";

type Account = { readonly id: number; readonly name: string; readonly note?: string };

export class Accounts {
  readonly #insert: StatementSync;
  readonly #byId: StatementSync;
  constructor(db: DatabaseSync) {
    this.#insert = db.prepare("INSERT INTO accounts (name, note) VALUES (:name, :note)");
    this.#byId = db.prepare("SELECT id, name, note FROM accounts WHERE id = :id");
  }
  add(name: string, note: Option<string>): void {
    this.#insert.run({ name, note: note ?? null });
  }
  // No such row is `undefined`; a row that doesn't fit `Account` is an error.
  find(id: number): JsonResult<Option<Account>> {
    const row = this.#byId.get({ id });
    return row === undefined ? undefined : __jsonValidate<Account>(row, __v0);
  }
}
// ---- generated by safe-ts: JSON validators ----
type __T0 = { "id": number; "name": string; "note"?: string; };
function __v0(v: unknown, p: string): __JsonResult<__T0> {
  if (!__jsonIsObject(v)) return __jsonFail(p, "object", v);
  const __j1 = v["id"];
  if (typeof __j1 !== "number") return __jsonFail(p + ".id", "number", __j1);
  const __j2 = __j1;
  const __j3 = v["name"];
  if (typeof __j3 !== "string") return __jsonFail(p + ".name", "string", __j3);
  const __j4 = __j3;
  const __j5 = v["note"];
  let __j6!: (string) | (undefined);
  __j7: {
  if (typeof __j5 === "string") { __j6 = __j5; break __j7; }
  if (__j5 === undefined || __j5 === null) { __j6 = undefined; break __j7; }
  return __jsonFail(p + ".note", "string | nothing", __j5);
  }
  const out = { "id": __j2, "name": __j4 } as { "id": number; "name": string; "note"?: string; };
  if (__j6 !== undefined) out["note"] = __j6;
  return out;
}

When null means something of its own in your data ("category": null for "every category", where a missing key is an error), keep it with JsonNull: in a type for parseJson<T>, only a null fits it and the result keeps it; jsonNull writes one; RawJson keeps every null of a document, so it comes back out byte for byte.

x ?? undefined at an any boundary ​

A migration from null leaves bridges behind: value ?? undefined, written where a T | null met an Option<T>. Once the types on both sides are Option<T>, they do nothing, and removing them all and letting tsc (or vue-tsc) list what breaks is safe where the value has a type. Where it is any, it isn't: an editor library's node attrs, a getPosition() typed loosely, $el, a value read inside unsafe(...). The null there is real, TypeScript reports nothing when the bridge goes, and the null reaches code that tests for undefined. In one migration, 7 of 170 bridges were of this kind, and removing one broke a check.

Search for ?? undefined before removing them, and look at the type of each operand. At an any, don't keep the bare bridge either: turn the value into a checked Option once, with validate<T> or a named converter, so the boundary says what it accepts:

✓ Accepted0 diagnostics
ts
import { type JsonResult, validate } from "@evobug_com/safe-ts-std/json";
import { type Option, q } from "@evobug_com/safe-ts-std/result";

// The editor types a node's attrs as `any`, and an unset title is a real `null` there.
type LinkAttrs = { readonly href: string; readonly title?: string };

export function linkTitle(attrs: unknown): JsonResult<Option<string>> {
  const link = q(validate<LinkAttrs>(attrs));
  return link.title;
}
ts
import { parseJsonWith as __jsonParse, validateWith as __jsonValidate, jsonFail as __jsonFail, isJsonErr as __jsonIsErr, isJsonObject as __jsonIsObject, type JsonResult as __JsonResult } from "@evobug_com/safe-ts-std/json"; import { type JsonResult, validate } from "@evobug_com/safe-ts-std/json";
import { Err as __qErr } from "@evobug_com/safe-ts-std/result"; import { type Option, q } from "@evobug_com/safe-ts-std/result";

// The editor types a node's attrs as `any`, and an unset title is a real `null` there.
type LinkAttrs = { readonly href: string; readonly title?: string };

export function linkTitle(attrs: unknown): JsonResult<Option<string>> {
  const __q1 = __jsonValidate<LinkAttrs>(attrs, __v0); if (__q1 instanceof __qErr) return __q1; const link = __q1;
  return link.title;
}
// ---- generated by safe-ts: JSON validators ----
type __T0 = { "href": string; "title"?: string; };
function __v0(v: unknown, p: string): __JsonResult<__T0> {
  if (!__jsonIsObject(v)) return __jsonFail(p, "object", v);
  const __j1 = v["href"];
  if (typeof __j1 !== "string") return __jsonFail(p + ".href", "string", __j1);
  const __j2 = __j1;
  const __j3 = v["title"];
  let __j4!: (string) | (undefined);
  __j5: {
  if (typeof __j3 === "string") { __j4 = __j3; break __j5; }
  if (__j3 === undefined || __j3 === null) { __j4 = undefined; break __j5; }
  return __jsonFail(p + ".title", "string | nothing", __j3);
  }
  const out = { "href": __j2 } as { "href": string; "title"?: string; };
  if (__j4 !== undefined) out["title"] = __j4;
  return out;
}

What changes on the wire ​

JSON has no undefined, so moving from null to undefined changes what JSON.stringify writes:

ValueJSON.stringify writes
{ reason: null }{"reason":null}
{ reason: undefined }{}: the key is left out
[undefined][null]
null"null"
undefinedundefined, not a string at all

TypeScript types the result as string every time. After the migration:

  • A field that was null is now missing from the message. A receiver that reads it with ?? or == null doesn't notice. One that requires the key, or tests body.reason === null, sees a different message.
  • A whole value that was null gives undefined instead of the text null. In a template it becomes the text undefined: `data: ${JSON.stringify(event)}` sends data: undefined on an event stream, and the client's JSON.parse fails on it, so the event is lost.

When a protocol needs an explicit null, write it where the JSON is built. A null in an object literal passed to JSON.stringify is outside code's null, so no-null allows it:

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

type Restart = { readonly id: string; readonly reason: Option<string> };

// The admin protocol wants `"reason": null` when there is none, not a missing key.
export function restartMessage(id: string, reason: Option<string>): string {
  if (reason === undefined) return JSON.stringify({ type: "restart", id, reason: null });
  return JSON.stringify({ type: "restart", id, reason });
}

// A missing event still sends valid JSON.
export function eventLine(event: Option<Restart>): string {
  return `data: ${event === undefined ? "null" : JSON.stringify(event)}\n\n`;
}

On the way in, parseJson<T> turns null back into undefined, so both sides of your code agree again. Where the protocol tells null apart from a missing key, keep it on both ends with JsonNull (reason: Option<string> | JsonNull, written as jsonNull).

Where to look, by project shape ​

Before the change, list every place a value leaves the program, and check what the receiver does with a missing key:

  • You call JSON.stringify yourself (fetch with body: JSON.stringify(order), a WebSocket send, a log line): the table above applies at each call, and JSON.stringify calls are easy to find.
  • A client library serialises for you: axios (data), generated request functions such as js-from-routes', ActionCable's perform, a GraphQL client's variables. They call JSON.stringify inside, so there is no call in your code to find, and a key whose value is now undefined silently leaves the request. Search for the library's entry points (axios.post, .perform(, the generated functions) and read each body.
  • The server treats a missing key differently from null. Typical for an update: Rails' update(params.permit(:due_date)) clears the date for "due_date": null and keeps it for a missing key. A "clear the date" request that sent null now changes nothing, and says so nowhere. Write jsonNull in those bodies, where the body is built.
  • Text built from a value: `${value}` and String(value) give "undefined" where they gave "null", in a URL, a query string, a FormData field or a cache key.
  • Stored data: localStorage, IndexedDB and files written before the change still hold null. Read them through validate<T>, which accepts both.

Compare the request bodies of the old and the new build on the same pages (a browser smoke): it finds what a search missed.

A transport adapter: a step, not the target ​

With a null-heavy backend, one pair of converters on the client library (null to undefined on every response, undefined to null on every request) turns thousands of no-null findings into a rename, because the rest of the code never sees a null. One app went that way. The two halves are worth different things:

  • Inbound, null to undefined: fine to keep, since it is what validate<T> does anyway. Better, replace it with validate<T> at each read, which also checks the shape.
  • Outbound, undefined to null: only a step. It keeps the wire as it was while the types change, but it makes undefined mean "clear" in every body, the opposite of what it means everywhere else (leave it out, unchanged). A stray undefined then clears data on the server, and the code grows two spellings of "clear" (jsonNull and undefined). It also changes bodies on the day it goes in: a key the code leaves as undefined today was left out, and starts going out as null. Audit every request body when you install it, and remove it one endpoint at a time: decide per field whether the server wants a missing key or a null, write jsonNull where it wants null, and take the endpoint out of the adapter.

The target is no outbound rewrite at all: a null goes out only where a body is built and the protocol asks for one. The idiomatic rule undefined-to-null reports such a replacer or key walk.

Sending "clear this field" ​

A request that changes some fields of a record (PATCH /issues/1) has three answers per field: leave it, clear it, set it. Don't spell "clear" with both jsonNull and undefined, and don't turn every undefined into null on the way out: then a value that is missing by mistake clears data on the server. Write the body as a Patch<T> from @evobug_com/safe-ts-std/patch, where each case has one spelling:

✓ Accepted0 diagnostics
ts
import type { Option } from "@evobug_com/safe-ts-std/result";
import { clear, keep, type Patch } from "@evobug_com/safe-ts-std/patch";

type Issue = { readonly title: string; readonly assignee: Option<string>; readonly dueAt: Option<string> };

export function unassign(title: Option<string>): string {
  const body: Patch<Issue> = { title: title ?? keep, assignee: clear };
  return JSON.stringify(body); // {"assignee":null}, or {"title":"…","assignee":null}
}
In the PatchSent asMeans
key left out, or keep (undefined)the key left outleave it as it is
clear (a JSON null)nullclear it
a valuethe valueset it

undefined never clears a field, and only a field that may be missing in T (Option<T>, field?:) can be cleared: { title: clear } doesn't compile. The object is already what goes on the wire, so JSON.stringify writes it as it is and isn't reported, and parseJson<Patch<Issue>> reads the same three cases on the server. Inside the app, "none" is undefined or an enum, not jsonNull: JsonNull and clear belong to the data that goes out.

When "missing" means two things ​

Say you want to tell "no such user" apart from "user has no nickname". Option<Option<string>> looks like it could, but both cases are just undefined at runtime.

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

export function nickname(id: string): Option<Option<string>> {
  return id === "42" ? "Ada" : undefined;
}

Give each case a name with an enum:

✓ Accepted0 diagnostics
ts
import { constructors, type Enum } from "@evobug_com/safe-ts-std/enum";

export type Nickname = Enum<{
  NoUser: {};
  NoNickname: {};
  Nickname: { value: string };
}>;
export const Nickname = constructors<Nickname>();

export function nickname(id: string): Nickname {
  if (id !== "42") return Nickname.NoUser();
  return Nickname.Nickname({ value: "Ada" });
}
ts
import { constructors, type Enum } from "@evobug_com/safe-ts-std/enum";

export type Nickname = Enum<{
  NoUser: {};
  NoNickname: {};
  Nickname: { value: string };
}>;
export const Nickname = constructors<Nickname>();

export function nickname(id: string): Nickname {
  if (id !== "42") return ({ tag: "NoUser" } satisfies Nickname as Nickname);
  return ({ tag: "Nickname", value: "Ada" } satisfies Nickname as Nickname);
}

undefined for "not loaded" where null meant "none" ​

Code written for a null-heavy backend often tells two states apart by which nothing it sees: the key is missing (undefined) while a record isn't loaded yet, and the server's null means "loaded, and there is none". Once the server's null turns into undefined on the way in, record[field] === undefined matches both: the field is fetched again and again, or a spinner never stops. TypeScript says nothing, since both sides are now Option<T>.

Find these places before converting: comparisons with undefined or in tests on fields that come from the server, above all a field the code also compares with null. A type probe lists them for you: replace each x === null / x === undefined with a call that states what x can hold, and the compiler names the ones that are wrong:

ts
// probe.ts: delete it afterwards.
type Holds<T> = null extends T ? (undefined extends T ? "both" : "null") : undefined extends T ? "undefined" : "neither";
export declare function probe<T>(value: T, holds: Holds<T>): boolean;

// probe(record.dueDate, "neither"): the error says `"both"` where both states can occur.

Then give the states names: an Enum, or the AsyncState below.

"Asked, and there is none" inside the app ​

jsonNull is for data on the wire. Inside the app, keeping it as a third value (Option<T | JsonNull>, "undefined is not asked yet, jsonNull is asked and empty") brings back the two kinds of nothing, under another name. For a value a request fills in, use AsyncState<Option<T>, E> (from @evobug_com/safe-ts-std/async-state, what useTask keeps): Idle and Loading are "not asked yet", Ready with undefined is "asked, and there is none", and Failed is a failure, which never turns into "none". For anything else, an Enum with a variant per case, as above. With the idiomatic rules on, json-null-in-app reports JsonNull kept as app state, and null-or-undefined-check a strict test for one of null and undefined on a value whose type holds both.

✓ Accepted0 diagnostics
ts
import { AsyncState } from "@evobug_com/safe-ts-std/async-state";
import { match } from "@evobug_com/safe-ts-std/enum";
import type { Option } from "@evobug_com/safe-ts-std/result";

type Reviewer = { readonly name: string };

export function reviewerLine(reviewer: AsyncState<Option<Reviewer>, Error>): string {
  return match(reviewer, {
    Idle: () => "No reviewer requested",
    Loading: () => "Looking for a reviewer…",
    Ready: ({ value }) => value?.name ?? "No reviewer",
    Failed: ({ error }) => `Couldn't load the reviewer: ${error.message}`,
  });
}

export const nobody: AsyncState<Option<Reviewer>, Error> = AsyncState.Ready({ value: undefined });
ts
import { AsyncState } from "@evobug_com/safe-ts-std/async-state";
import { unreachable as __matchUnreachable } from "@evobug_com/safe-ts-std/enum"; import { match } from "@evobug_com/safe-ts-std/enum";
import type { Option } from "@evobug_com/safe-ts-std/result";

type Reviewer = { readonly name: string };

export function reviewerLine(reviewer: AsyncState<Option<Reviewer>, Error>): string {
  { const __ms1 = reviewer; let __mv1: string; switch (__ms1.tag) {
    case "Idle": { __mv1 = "No reviewer requested"; break; }
    case "Loading": { __mv1 = "Looking for a reviewer…"; break; }
    case "Ready": { const { value } = __ms1; __mv1 = value?.name ?? "No reviewer"; break; }
    case "Failed": { const { error } = __ms1; __mv1 = `Couldn't load the reviewer: ${error.message}`; break; } default: __mv1 = __matchUnreachable(__ms1); } return __mv1; }

}

export const nobody: AsyncState<Option<Reviewer>, Error> = AsyncState.Ready({ value: undefined });
The same trap with unknown

Result<unknown, E> means unknown | Err<E>, and that is just unknown, so callers are never made to check for the error. The checker reports it (no-unknown-in-result). Check the value against a real type first: see the JSON guide.

Rules in this guide: no-null, no-undefined-check-for-null, no-null-check-for-undefined, no-nested-option, no-unknown-in-result

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