Skip to main content

isPendingOption

@ts-rust/std


@ts-rust/std / Option / isPendingOption

Function: isPendingOption()

function isPendingOption(x): x is PendingOption<unknown>;

Defined in: packages/std/src/option/option.ts:205

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

This type guard verifies whether the input is a PendingOption, indicating it wraps a Promise resolving to an Option (either Some or None).

Parameters

ParameterTypeDescription

x

unknown

The value to check.

Returns

x is PendingOption<unknown>

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

Example

const x: unknown = pendingOption(some(42));
const y: unknown = pendingOption(none<number>());
const z: unknown = some(42); // Not a PendingOption

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

if (isPendingOption(x)) {
expect(await x).toStrictEqual(some(42)); // Type narrowed to PendingOption<unknown>
}