Type alias Result<T, E>

Result<T, E>: Ok<T> | Err<E>

Represents the result of an operation that can either succeed with a value or fail with an error.

Type Parameters

  • T

    The type of the success value.

  • E extends string | Error

    The type of the error value.

Example

const orResult: Result<number, string> = ok(42);
const errorResult: Result<number, string> = error("An error occurred");

orResult.get(); // Returns 42
errorResult.get(); // Throws Error("An error occurred")

orResult.extract(); // Returns {value: 42}
errorResult.extract(); // Returns {error: "An error occurred"}

orResult.toOptional(); // Optional with value 42
errorResult.toOptional(); // Optional with no value

Since

version 1.2.0

Author

Manuel Santos ney.br.santos@gmail.com

Generated using TypeDoc