Aller au contenu principal

errAsync()

errAsync<T, E>(err): ResultAsync<T, E>

Creates a new error async result.

Uses unknown types for maximum type safety and flexibility.


Type Parameters

T: T = never

The type of the success value (defaults to never)

E: E = unknown

The type of the error value (defaults to unknown)


Parameters

err: E

The error to wrap in an error result


Returns: ResultAsync<T, E>

A new ResultAsync that will resolve to Err(err)


Since

2.0.0


Example

const error = errAsync("Something went wrong");
const resolved = await error; // Err("Something went wrong")

const networkError = errAsync(new Error("Network timeout"));
const result = await networkError; // Err(Error: Network timeout)

const customError = errAsync({ code: 500, message: "Internal error" });
const custom = await customError; // Err({ code: 500, message: "Internal error" })