A Result represents success (Ok) or failure (Err).

The behavior of this type is checked by TypeScript at compile time, and bears no runtime overhead other than the very small cost of the container object.

Properties

Properties

err: {
    <T = never, E = unknown>(): Result<T, Unit>;
    <T = never, E = unknown>(error: E): Result<T, E>;
}

Type declaration

    • <T = never, E = unknown>(): Result<T, Unit>
    • Create an instance of Err.

      const anErr = Result.err('alas, failure');
      

      Type Parameters

      • T = never
      • E = unknown

      Returns Result<T, Unit>

    • <T = never, E = unknown>(error: E): Result<T, E>
    • Create an instance of Err.

      const anErr = Result.err('alas, failure');
      

      Type Parameters

      • T = never
      • E = unknown

      Parameters

      • error: E

        The value to wrap in an Err.

      Returns Result<T, E>

ok: { (): Result<Unit, never>; <T, E = never>(value: T): Result<T, E> }

Type declaration

    • (): Result<Unit, never>
    • Create an instance of Ok.

      Note that you may explicitly pass Unit to the ok constructor to create a Result<Unit, E>. However, you may not call the ok constructor with null or undefined to get that result (the type system won't allow you to construct it that way). Instead, for convenience, you can simply call Result.ok(), which will construct the type correctly.

      Returns Result<Unit, never>

    • <T, E = never>(value: T): Result<T, E>
    • Type Parameters

      • T
      • E = never

      Parameters

      • value: T

        The value to wrap in an Ok.

      Returns Result<T, E>