UNPKG

@calljmp/cli

Version:
77 lines 2.24 kB
/** * Represents a value that may be pending, succeeded, or errored. * Useful for tracking async state in a type-safe way. */ export declare class Value<T> { private _value; private _pending; private _error; constructor(value: T | null, pending?: boolean, error?: Error | null); /** * The current value, or null if not set. */ get value(): T | null; /** * Whether the value is currently pending. */ get pending(): boolean; /** * Whether the value has succeeded (not pending and no error). */ get succeeded(): boolean; /** * Whether the value has errored (not pending and has error). */ get errored(): boolean; /** * The error, if any. */ get error(): Error | null; /** * Whether the value is not null. */ get hasValue(): boolean; /** * Returns an empty Value. */ static empty<T>(): Value<T>; /** * Returns a pending Value. */ static pending<T>(): Value<T>; /** * Returns a Value in the error state. * @param error The error to set */ static error<T>(error: Error): Value<T>; /** * Returns a Value with the given value. * @param value The value to set */ static of<T>(value: T): Value<T>; /** * Converts a value or Value into a Value. * @param value The value or Value to convert */ static from<T>(value: T | Value<T>): Value<T>; /** * Maps a Value<T> to Value<U> using the provided function. * @param value The Value to map * @param fn Mapping function */ static map<T, U>(value: Value<T>, fn: (value: T) => U): Value<U>; /** * Flat maps a Value<T> to Value<U> using the provided function. * @param value The Value to flatMap * @param fn Flat mapping function */ static flatMap<T, U>(value: Value<T>, fn: (value: T) => Value<U>): Value<U>; /** * Combines two Value instances into one using the provided function. * @param a First Value * @param b Second Value * @param fn Combining function */ static combine<T, U, V>(a: Value<T>, b: Value<U>, fn: (a: T, b: U) => V): Value<V>; } //# sourceMappingURL=value.d.ts.map