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 Alias | Description |
|---|---|
| InferOption | Extracts the value type from an Option or Some. |
Functions
| Function | Description |
|---|---|
| fromNullable | Converts a nullable value to an Option. |
| isNone | Type guard for None. |
| isSome | Type guard for Some. |
| some | Creates a Some. |
Interfaces
| Interface | Description |
|---|---|
| None | Absent value in an Option. |
| Some | Present value in an Option. |
Type Aliases
| Type Alias | Description |
|---|---|
| Option | Optional value. |
Variables
| Variable | Description |
|---|---|
| none | Shared None instance. |