method Result.err
Result.err<E extends BaseError, T = never>(error: E): Result<T, E>

Creates a failed Result containing an error.

Examples

Example 1

const result = Result.err(new ValidationError("Invalid input"));
const value = result.take();
if (isErr(value)) {
  console.error(value.error.message); // "Invalid input"
}

Type Parameters

E extends BaseError

The type of the error (must extend BaseError)

T = never

The type of the success value (defaults to never)

Parameters

error: E

The error to wrap

Return Type

A Result instance containing the error

Usage

import { Result } from "result/mod.ts";