no-nested-option
Option<Option<T>> and Option<T | undefined> are not allowed.
Why: Option<T> is T | undefined, so nesting it gives T | undefined | undefined: "absent" and "present but empty" are the same value at runtime, even though the type looks like it could tell them apart. Guide: Absence.
✕ Rejectedno-nested-option
ts
import type { Option } from "@evobug_com/safe-ts-std/result";
export function lookup(cache: ReadonlyMap<string, Option<string>>, key: string): Option<Option<string>> {
return cache.get(key);
}✅ Accepted: name the cases
✓ Accepted0 diagnostics
ts
import { constructors, type Enum } from "@evobug_com/safe-ts-std/enum";
import type { Option } from "@evobug_com/safe-ts-std/result";
export type Lookup = Enum<{ Missing: {}; Cached: { value: Option<string> } }>;
export const Lookup = constructors<Lookup>();
export function lookup(cache: ReadonlyMap<string, Option<string>>, key: string): Lookup {
return cache.has(key) ? Lookup.Cached({ value: cache.get(key) }) : Lookup.Missing();
}ts
import { constructors, type Enum } from "@evobug_com/safe-ts-std/enum";
import type { Option } from "@evobug_com/safe-ts-std/result";
export type Lookup = Enum<{ Missing: {}; Cached: { value: Option<string> } }>;
export const Lookup = constructors<Lookup>();
export function lookup(cache: ReadonlyMap<string, Option<string>>, key: string): Lookup {
return cache.has(key) ? ({ tag: "Cached", value: cache.get(key) } satisfies Lookup as Lookup) : ({ tag: "Missing" } satisfies Lookup as Lookup);
}