API reference › @evolu/common › Type › greaterThanBigInt

function greaterThanBigInt<Min extends bigint>(
  min: ValidateBrandFactoryBigInt<Min>,
): BrandFactory<`GreaterThan${Min}n`, bigint, GreaterThanBigIntError<Min>>;

Defined in: packages/common/src/Type.ts:12431

Bigint Brand requiring a value greater than min.

The bigint counterpart of greaterThan for parents with a bigint Output, such as BigInt, Int64, and UInt64. The Brand name ends with n, so greaterThanBigInt(10n) and greaterThan(10) create distinct Brands. For positive bigints, use greaterThanBigInt(0n).

Example

import {
  assertEqual,
  assertErr,
  assertOk,
  assertType,
  greaterThanBigInt,
  Int64,
  type Brand,
} from "@evolu/common";

const PositiveInt64 = greaterThanBigInt(0n)(Int64);

assertType<
  typeof PositiveInt64.Output,
  bigint & Brand<"Int64"> & Brand<"GreaterThan0n">
>();
assertOk(PositiveInt64.fromUnknown(1n), 1n);

const zero = PositiveInt64.fromUnknown(0n);
assertErr(zero, { type: "GreaterThan0n", value: 0n, min: 0n });
assertEqual(
  PositiveInt64.formatError(zero.error),
  "The value 0 must be greater than 0.",
);