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

// A cache that can store any value, including null and undefined
const cache = new Map<string, Option<unknown>>();

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

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

isSome(get("a")); // true — value is null
isSome(get("b")); // true — value is undefined
isNone(get("c")); // true — key doesn't exist

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.