Option<T> models the explicit presence (Some) or absence (None) of a value. Under the hood, it is an alias for Result<NonNullable<T>, never>, which means it shares the full Result API: .map(), .andThen(), .unwrapOr(), and everything else.
Creating options
nullable(value)
Converts any nullable value (T | null | undefined) into an Option<T>:
optionFromGuard(value, guard)
Creates an Option from an unknown value and a type guard. Returns Some if the guard passes, None otherwise:
The full Result API
BecauseOption<T> is Result<NonNullable<T>, never>, every Result method is available:
Converting to Result
Use.orElse() to assign a specific error to the None case, converting an Option to a Result:
Upgrading to Task
Option is ideal for synchronous lookups (like reading a cache or an environment variable). When you need to feed that optional value into an async pipeline, upgrade it to a Task with Task.fromOption():