API reference › @evolu/common › Assert › assertOk
Call Signature
function assertOk<R>(result: R): asserts result is Extract<R, Ok<unknown>>;
Defined in: packages/common/src/Assert.ts:1198
Asserts that a Result is an Ok and narrows it, optionally comparing its value.
When an expected value is provided, it is compared using assertEqual semantics by default. Pass a custom Eq for different equality semantics.
Example
import {
assertOk,
assertType,
ok,
type Ok,
type Result,
type Typed,
} from "@evolu/common";
interface User {
readonly id: string;
}
interface UserNotFoundError extends Typed<"UserNotFound"> {}
const result: Result<User, UserNotFoundError> = ok({ id: "user-1" });
assertOk(result, { id: "user-1" });
assertType<typeof result, Ok<User>>();
Call Signature
function assertOk<R>(
result: R,
expectedValue: InferOk<R>,
eq: Eq<InferOk<R>>,
): asserts result is Extract<R, Ok<unknown>>;
Defined in: packages/common/src/Assert.ts:1201
Asserts that a Result is an Ok and narrows it, optionally comparing its value.
When an expected value is provided, it is compared using assertEqual semantics by default. Pass a custom Eq for different equality semantics.
Example
import {
assertOk,
assertType,
ok,
type Ok,
type Result,
type Typed,
} from "@evolu/common";
interface User {
readonly id: string;
}
interface UserNotFoundError extends Typed<"UserNotFound"> {}
const result: Result<User, UserNotFoundError> = ok({ id: "user-1" });
assertOk(result, { id: "user-1" });
assertType<typeof result, Ok<User>>();
Call Signature
function assertOk<R>(
result: R,
expectedValue: unknown,
): asserts result is Extract<R, Ok<unknown>>;
Defined in: packages/common/src/Assert.ts:1206
Asserts that a Result is an Ok and narrows it, optionally comparing its value.
When an expected value is provided, it is compared using assertEqual semantics by default. Pass a custom Eq for different equality semantics.
Example
import {
assertOk,
assertType,
ok,
type Ok,
type Result,
type Typed,
} from "@evolu/common";
interface User {
readonly id: string;
}
interface UserNotFoundError extends Typed<"UserNotFound"> {}
const result: Result<User, UserNotFoundError> = ok({ id: "user-1" });
assertOk(result, { id: "user-1" });
assertType<typeof result, Ok<User>>();