API reference@evolu/commonResult › Err

Defined in: packages/common/src/Result.ts:299

An error Result.

The error property can be any type that describes the error. For domain errors, define a plain interface extending Typed.

Example

import {
  assertErr,
  assertOk,
  err,
  ok,
  type Result,
  type Typed,
} from "@evolu/common";

interface User {
  readonly id: string;
}

const users = new Map<string, User>([["user-1", { id: "user-1" }]]);
const findUser = (id: string): Result<User, NotFoundError> => {
  const user = users.get(id);
  if (user == null) return err({ type: "NotFound", id });
  return ok(user);
};

interface NotFoundError extends Typed<"NotFound"> {
  readonly id: string;
}

assertOk(findUser("user-1"), { id: "user-1" });
assertErr(findUser("missing"), {
  type: "NotFound",
  id: "missing",
});

Properties

error

readonly error: E;

Defined in: packages/common/src/Result.ts:301


ok

readonly ok: false;

Defined in: packages/common/src/Result.ts:300