API reference › @evolu/common › Result › anyResult
function anyResult<T>(
results: T,
): Result<InferOk<T[number]>, InferErr<T[number]>>;
Defined in: packages/common/src/Result.ts:1391
Returns the first successful Result.
If all results fail, returns the last error.
Requires a non-empty array — there's no "first success" with zero participants. Use isNonEmptyArray to guard.
Example
import {
anyResult,
assertOk,
assertType,
err,
ok,
type Result,
type Typed,
} from "@evolu/common";
const getCachedPrice = (): Result<number, CacheMissError> =>
err({ type: "CacheMiss" });
interface CacheMissError extends Typed<"CacheMiss"> {}
const number = anyResult([getCachedPrice(), ok(42)]);
assertType<Result<number, CacheMissError>, typeof number>();
assertOk(number, 42);