The type of the value contained in the Option
Readonly_Readonly[toReadonlyisWhether this Option contains no value
The number of elements in this Option (0 or 1)
ReadonlyvalueThe contained value (undefined for None)
Checks if this Option contains the specified value
The value to check for
true if this Option contains the value, false otherwise
Counts elements that satisfy the predicate. For single-value containers: returns 0 or 1 For collections: returns the count of matching elements
Tests whether the value, if there is one, satisfies the predicate. The dual of exists, and
Scala's forall: None gives true, the same way [].every(p) does.
The predicate to test the value with
true for None, otherwise p(value)
Tests whether any element satisfies the predicate. For single-value containers: tests the single value For collections: returns true if any element matches
Returns the contained value, or calls the never-returning handler if None.
Use this when you have a helper like (msg) => fail(msg, 2) that terminates the
program — the result type is unconditionally T, so you avoid the TypeScript
narrowing trap where if (o.isNone()) fail(...) fails to narrow o.value when
fail is an arrow function typed as (...): never.
Applies an effect function to each element. For single-value containers: applies to the value if present For collections: applies to each element
Returns the contained value, or calls defaultValue if None. The default is lazy: it runs
only on None. The default is typed against T first, so () => "light" on an
Option<"light" | "dark"> stays "light" | "dark". A default of another type widens the
result to T | T2, which keeps Option covariant in T.
The contained value or the default, typed as T | T2
Returns this Option if it contains a value, otherwise calls alternative for another Option.
The alternative is lazy: it runs only on None. It may hold a different type; the result
widens to Option<T | T2>.
This Option or the alternative, typed as Option<T | T2>
Returns the contained value or throws an error if None
Optionalerror: Error | (() => Error)
Optional error to throw, or a builder that makes one (called only on None). If not provided, throws a default error
The contained value
Returns the contained value or undefined if None
The contained value or undefined
Converts this Option to a plain readonly array.
[value] if Some, [] if None. Symmetric with toList() but
skips the List wrapper for code that just wants Array-prototype methods
or spread into another array.
Custom JSON serialization producing the canonical @functype-marked
envelope so native JSON.stringify recursion (e.g. inside a plain
object) emits a round-trip-able shape.
Converts this container to a Promise
The behavior depends on the implementing container:
A Promise that resolves or rejects based on the container's state
Returns a string representation of this Option
A string representation
Converts this monad to a Try.
Conversion rules:
A Try containing Success with the value or Failure with an appropriate error
Returns a simple object representation of this Option
An object with _tag and value properties
What every Option has, Some or None.
Option<T>is the union ofSomeOf<T>andNoneOf<T>, so TypeScript narrows it onisSome(),isNone()and_tag, as it does Either.