json-null-in-app
JsonNull used as a second "none" inside the app: Option<T | JsonNull>, T | JsonNull | undefined for a variable, parameter or return type, a Ref<T | JsonNull>, and jsonNull put into reactive state (ref(jsonNull), state.value = jsonNull). An idiomatic rule: reported only with "safe-ts": { "idiomatic": true } in package.json.
Why: JsonNull is the null of JSON: for a protocol where null and a missing key mean different things, written where the body is built or read. As app state it becomes a second "none" next to undefined, and nothing says which one means "not loaded" and which "asked, and there is none". Code then tests the wrong one, and a failure turned into jsonNull looks like an answer. Name the states instead. Guide: Absence.
✕ Rejectedjson-null-in-app
ts
import { type JsonNull, jsonNull } from "@evobug_com/safe-ts-std/json";
import type { Option } from "@evobug_com/safe-ts-std/result";
type Manager = { readonly name: string };
export function managerLabel(manager: Option<Manager | JsonNull>): string {
if (manager === undefined) return "…";
return manager === jsonNull ? "no manager" : manager.name;
}✅ Accepted: an Enum names each state
✓ Accepted0 diagnostics
ts
import { type Enum, match } from "@evobug_com/safe-ts-std/enum";
type Manager = { readonly name: string };
type ManagerState = Enum<{ NotLoaded: {}; None: {}; Some: { manager: Manager } }>;
export function managerLabel(state: ManagerState): string {
return match(state, { NotLoaded: () => "…", None: () => "no manager", Some: ({ manager }) => manager.name });
}ts
import { unreachable as __matchUnreachable } from "@evobug_com/safe-ts-std/enum"; import { type Enum, match } from "@evobug_com/safe-ts-std/enum";
type Manager = { readonly name: string };
type ManagerState = Enum<{ NotLoaded: {}; None: {}; Some: { manager: Manager } }>;
export function managerLabel(state: ManagerState): string {
{ const __ms1 = state; let __mv1: string; switch (__ms1.tag) { case "NotLoaded": { __mv1 = "…"; break; } case "None": { __mv1 = "no manager"; break; } case "Some": { const { manager } = __ms1; __mv1 = manager.name; break; } default: __mv1 = __matchUnreachable(__ms1); } return __mv1; }
}Loaded by a task, the same thing is an AsyncState<Option<Manager>, E>: Loading is "not loaded", Ready with undefined is "asked, and there is none".
Not reported: a wire type where the key may be left out or sent as null (dueDate?: string | JsonNull), jsonNull written into a body (JSON.stringify({ dueDate: due ?? jsonNull })), a parse type, and test files (test data shaped like parsed JSON).