Skip to main content

Result <T, E>

A class representing the result of a failable operation

Index

Constructors

Properties

Accessors

Methods

Constructors

constructor

  • new Result<T, E>(value: T, error?: E): Result<T, E>
  • Create a new Result representing the status of a failable operation


    Type parameters

    • T
    • E: Error = Error

    Parameters

    • value: T
    • optionalerror: E = null

    Returns Result<T, E>

Properties

error

error: E

value

value: T

Accessors

err

  • get err(): boolean
  • Returns whether the operation was a failure


    Returns boolean

ok

  • get ok(): boolean
  • Returns whether the operation was a success


    Returns boolean

Methods

unwrap

  • unwrap(): T
  • Unwrap the result This either returns the successful return of the operation, or throws the error it reported


    Returns T

staticfailure

  • failure(error: Error): Result<any, Error>
  • Build a Result for a failed operation


    Parameters

    • error: Error

    Returns Result<any, Error>

staticsuccess

  • success<T>(value: T): Result<T, any>
  • Build a Result for a successful operation


    Type parameters

    • T

    Parameters

    • value: T

    Returns Result<T, any>