API reference@evolu/common › Option

Optional value container.

Distinguishes absence from values like null or undefined.

Use Option when the value itself can be null or undefined. For APIs where null means "not found", just use T | null directly.

Example

import { isNone, isSome, none, type Option, some } from "@evolu/common";

const cache = new Map<string, Option<unknown>>();

const get = (key: string): Option<unknown> => cache.get(key) ?? none;

cache.set("a", some(null));
cache.set("b", some(undefined));

const a = get("a");
assert(isSome(a));
expect(a.value).toBeNull();
expect(isSome(get("b"))).toBe(true);
expect(isNone(get("c"))).toBe(true);

Utilities

Type AliasDescription
InferOptionExtracts the value type from an Option or Some.

Functions

FunctionDescription
fromNullableConverts a nullable value to an Option.
isNoneType guard for None.
isSomeType guard for Some.
someCreates a Some.

Interfaces

InterfaceDescription
NoneAbsent value in an Option.
SomePresent value in an Option.

Type Aliases

Type AliasDescription
OptionOptional value.

Variables

VariableDescription
noneShared None instance.