Skip to main content

pendingErr

@ts-rust/std


@ts-rust/std / Result / pendingErr

Function: pendingErr()

function pendingErr<T, E>(error): PendingResult<Awaited<T>, Awaited<E>>;

Defined in: packages/std/src/result/result.ts:403

Creates a PendingResult\<T, E\> that resolves to Err containing the awaited error.

Takes an error or promise and wraps its resolved result in an Err, ensuring the error type is Awaited to handle any PromiseLike input.

Type Parameters

Type ParameterDescription

T

The type of the potential value.

E

The type of the input error or promise.

Parameters

ParameterTypeDescription

error

| E | CheckedError<E> | Promise<E> | Promise<CheckedError<E>>

The error or promise to wrap in Err.

Returns

PendingResult<Awaited<T>, Awaited<E>>

A PendingResult resolving to Err with the awaited error.

Example

const x = pendingErr<number, string>("failure");
const y = pendingErr<string, number>(Promise.resolve(42));

expect(await x).toStrictEqual(err("failure"));
expect(await y).toStrictEqual(err(42));