Import
import { Optimistic } from "@typed/async-data";Signatures
export interface Optimistic<A, E> {
readonly _tag: "Optimistic";
readonly value: A;
readonly previous: AsyncData<A, E>;
}Why
Preserving history makes rollback and nested optimistic transformations explicit rather than hiding them in renderer state.
Ownership and lifetime
This plain wrapper acquires no resources and retains its previous state; readonly is compile-time only.
Property: _tag
The discriminant for optimistic state.
Property: _tag: Why
The literal tag enables explicit optimistic handling and cycle-safe traversal.
Property: _tag: Ownership and lifetime
Inherits the resource-free lifetime of its enclosing state.
Property: previous
The state to restore or inspect beneath this optimistic layer.
Property: previous: Why
Explicit history supports deterministic rollback and transformation of nested optimistic states.
Property: previous: Ownership and lifetime
Inherits the enclosing optimistic wrapper’s resource-free lifetime.
Property: value
The value currently presented optimistically.
Property: value: Why
Separating the provisional value from history makes pending intent directly observable.
Property: value: Ownership and lifetime
Inherits the enclosing state’s lifetime; the caller retains ownership of the referenced value.
Examples
import { optimistic, success } from "@typed/async-data"
const state = optimistic(success(1), 2)