variable / @typed/async-data

isPending

Tests whether the base state is loading or refreshing through optimistic history.

Package version
1.0.0-beta.7
Category
State inspection
Since
1.0.0

Import

import { isPending } from "@typed/async-data";

Signatures

export declare const isPending: <A, E>(asyncData: AsyncData<A, E>) => asyncData is Loading | Refreshing<A, E>;

Why

Pending status follows the underlying operation rather than disappearing when optimistic values are layered above it; cycles return false.

Known type/runtime discrepancy: an Optimistic wrapper over a pending base returns true at runtime, but the existing type predicate narrows to Loading | Refreshing<A, E> and excludes Optimistic. Do not use this function to narrow before reading _tag; use it only as a pending-status boolean and refine the original value separately. The predicate is retained for compatibility and is not an accurate description of every true result.

Ownership and lifetime

This iterative predicate acquires no resources and retains no visited objects after returning.

Examples

import { isPending, loading, optimistic } from "@typed/async-data"
isPending(optimistic(loading(), "draft"))

Source