Options
Modules
  • Command
  • Localization
  • Logger
All
  • Public
  • Public/Protected
  • All
Menu

Class Result<T>

Represents the result of some operation. Can hold a value. Use isSome() to check if the result holds a value.

Typescript Note: isSome() and isError() both assert that the value field is not able to be undefined at run-time AND compile-time so you won't need to make any additional checks. 👍

Type parameters

  • T = any

Hierarchy

  • Result

Index

Properties

kind

kind: string

Optional value

value: T

The value this Result holds. Use isSome() or isError() to check that the value is not undefined/null

Methods

isCancellation

  • isCancellation(): boolean
  • Whether or not this Result is a Cancellation Result

    Returns boolean

isError

  • isError(): this is Required<Result<T>>
  • Whether or not this Result is an Error Result. Error Results will always have a defined value field containing the error the Result holds

    Returns this is Required<Result<T>>

isOk

  • isOk(): boolean
  • Whether or not this Result is an Ok Result. Does not indicate whether or not this Result holds a value. Use isSome() to check that value is not undefined/null

    Returns boolean

isSome

  • isSome(): this is Required<Result<T>>

Static cancel

  • Creates a Cancellation Result. Cancellation Results are used to signal that an operation (Rule, Middleware, Argument prompting, etc) has been cancelled and should exit silently.

    NOTE: Rules and Middleware can pass a Cancellation Result to the next function to exit silently, but they will also exit silently if the next function is never called, so the Cancellation Result is not really necessary for them. Cancellation Results are primarily used for Argument defaults to signal that a command should be canceled (Likely because the Argument default uses argument prompting and the prompt was canceled).

    Returns Result<any>

Static error

  • error<U>(error: U): Result<U>
  • Creates an Error Result. Must be given an Error. Error Results are used for passing errors from Rules, Middleware, and Argument resolvers so that they can more easily be passed around to error handlers

    Type parameters

    • U: Error

    Parameters

    • error: U

    Returns Result<U>

Static ok

  • Creates an Ok Result. Can be given a value. Ok Results represent the result of a successful operation

    Type parameters

    • U

    Parameters

    • Optional value: U

    Returns Result<U>

Generated using TypeDoc