Class ErrImpl<E>

Contains the error value

Type Parameters

  • E

Implements

Accessors

  • get stack(): string
  • Returns string

Constructors

  • Type Parameters

    • E

    Parameters

    • val: E

    Returns ErrImpl<E>

Methods

  • Calls mapper if the result is Ok, otherwise returns the Err value of self. This function can be used for control flow based on Result values.

    Parameters

    • op: unknown

    Returns Err<E>

  • Type Parameters

    • T2

    Parameters

    • val: T2

    Returns T2

    Deprecated

    in favor of unwrapOr

    See

    unwrapOr

  • Returns the contained Ok value, if exists. Throws an error if not.

    The thrown error's [cause'](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/cause) is set to value contained in Err`.

    If you know you're dealing with Ok and the compiler knows it too (because you tested isOk() or isErr()) you should use value instead. While Ok's expect() and value will both return the same value using value is preferable because it makes it clear that there won't be an exception thrown on access.

    Parameters

    • msg: string

      the message to throw if no Ok value.

    Returns never

  • Returns the contained Err value, if exists. Throws an error if not.

    Parameters

    • _msg: string

      the message to throw if no Err value.

    Returns E

  • Maps a Result<T, E> to Result<U, E> by applying a function to a contained Ok value, leaving an Err value untouched.

    This function can be used to compose the results of two functions.

    Parameters

    • _mapper: unknown

    Returns Err<E>

  • Maps a Result<T, E> to Result<T, F> by applying a function to a contained Err value, leaving an Ok value untouched.

    This function can be used to pass through a successful result while handling an error.

    Type Parameters

    • E2

    Parameters

    • mapper: ((err) => E2)
        • (err): E2
        • Parameters

          • err: E

          Returns E2

    Returns Err<E2>

  • Maps a Result<T, E> to Result<U, E> by either converting T to U using mapper (in case of Ok) or using the default_ value (in case of Err).

    If default is a result of a function call consider using mapOrElse instead, it will only evaluate the function when needed.

    Type Parameters

    • U

    Parameters

    • default_: U
    • _mapper: unknown

    Returns U

  • Maps a Result<T, E> to Result<U, E> by either converting T to U using mapper (in case of Ok) or producing a default value using the default function (in case of Err).

    Type Parameters

    • U

    Parameters

    • default_: ((error) => U)
        • (error): U
        • Parameters

          • error: E

          Returns U

    • _mapper: unknown

    Returns U

  • Returns Ok() if we have a value, otherwise returns other.

    other is evaluated eagerly. If other is a result of a function call try orElse() instead – it evaluates the parameter lazily.

    Type Parameters

    • T

    • E2

    Parameters

    Returns Result<T, E2>

    Example

    Ok(1).or(Ok(2)) // => Ok(1)
    Err('error here').or(Ok(2)) // => Ok(2)
  • Returns Ok() if we have a value, otherwise returns the result of calling other().

    other() is called only when needed and is passed the error value in a parameter.

    Type Parameters

    • T

    • E2

    Parameters

    • other: ((error) => Result<T, E2>)
        • (error): Result<T, E2>
        • Parameters

          • error: E

          Returns Result<T, E2>

    Returns Result<T, E2>

    Example

    Ok(1).orElse(() => Ok(2)) // => Ok(1)
    Err('error').orElse(() => Ok(2)) // => Ok(2)
  • Converts from Result<T, E> to Option<T>, discarding the error if any

    Similar to rust's ok method

    Returns Option<never>

  • Returns string

  • Returns the contained Ok value. Because this function may throw, its use is generally discouraged. Instead, prefer to handle the Err case explicitly.

    If you know you're dealing with Ok and the compiler knows it too (because you tested isOk() or isErr()) you should use value instead. While Ok's unwrap() and value will both return the same value using value is preferable because it makes it clear that there won't be an exception thrown on access.

    Throws if the value is an Err, with a message provided by the Err's value and [`cause'](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/cause) set to the value.

    Returns never

  • Returns the contained Ok value or a provided default.

    (This is the unwrap_or in rust)

    Type Parameters

    • T2

    Parameters

    • val: T2

    Returns T2

Properties

_stack: any
error: E
EMPTY: ErrImpl<void>

An empty Err