Skip to main content

abstractOption <T>

Represents an optional value. An Option is either a Some value containing a value, or a None value containing no value.

@example
let o: Option<number> = Option.some(42);
o = Option.none; // Marks the option as empty

Hierarchy

Index

Accessors

publicstaticnone

  • Returns a None value.

    @example
    let o: Option<number> = Option.none;

    Returns Option<never>

Methods

publicstaticall

  • all<T>(values: T): Option<{ -readonly [ K in string | number | symbol ]: OptionType<T[K<K>]> }>
  • Returns the array of Some values, if all are Some.

    @example
    const tuple = [Option.some(42), Option.some('42')] as const;
    Option.all(tuple); // Option<[number, string]>

    Type parameters

    Parameters

    • values: T

    Returns Option<{ -readonly [ K in string | number | symbol ]: OptionType<T[K<K>]> }>

publicstaticany

  • Returns the first Some value in the array, if any is Some.

    @example
    const tuple = [Option.none, Option.some(42), Option.some('42')] as const;
    Option.any(tuple); // Option<number | string>

    Type parameters

    Parameters

    • values: T

    Returns Option<OptionType<T[number]>>

publicstaticassert

  • assert<T>(option: Option<T>, type: typeof Some): asserts option is Some<T>
  • assert<T>(option: Option<T>, type: typeof None): asserts option is None
  • Asserts that the option is a Some value.

    @throws

    If the value is a None.


    Type parameters

    • T

    Parameters

    Returns asserts option is Some<T>

publicstaticis

  • Returns true if the option is a Some value.


    Type parameters

    • T

    Parameters

    Returns option is Some<T>

publicstaticsome

  • Returns a Some value.

    @example
    let o: Option<number> = Option.some(42);

    Type parameters

    • T

    Parameters

    • value: T

    Returns Option<T>

publicstaticunwrap

  • unwrap<T>(option: Option<T>): T
  • Unwraps the option, yielding the content of a Some.

    @throws

    If the value is a None.


    Type parameters

    • T

    Parameters

    Returns T

Page Options