Skip to main content

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" })