Skip to main content

isPendingResult

@ts-rust/std


@ts-rust/std / Result / isPendingResult

Function: isPendingResult()

function isPendingResult(x): x is PendingResult<unknown, unknown>;

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

Checks if a value is a PendingResult, narrowing its type to PendingResult<unknown, unknown>.

This type guard verifies whether the input is a PendingResult, indicating it wraps a Promise resolving to a Result (either Ok or Err).

Parameters

ParameterTypeDescription

x

unknown

The value to check.

Returns

x is PendingResult<unknown, unknown>

true if the value is a PendingResult, narrowing to PendingResult<unknown, unknown>.

Example

const x: unknown = pendingResult(ok<number, string>(42));
const y: unknown = pendingResult(err<number, string>("failure"));
const z: unknown = ok(42); // Not a PendingResult

expect(isPendingResult(x)).toBe(true);
expect(isPendingResult(y)).toBe(true);
expect(isPendingResult(z)).toBe(false);

if (isPendingResult(x)) {
// Type narrowed to PendingResult<unknown, unknown>
expect(await x).toStrictEqual(ok(42));
}