API reference › @evolu/common › Type › betweenBigInt
function betweenBigInt<Min extends bigint, Max extends bigint>(
min: ValidateBrandFactoryBigInt<Min>,
max: ValidateBrandFactoryBigInt<Max>,
): BrandFactory<`Between${Min}n-${Max}n`, bigint, BetweenBigIntError<Min, Max>>;
Defined in: packages/common/src/Type.ts:12693
Bigint Brand requiring a value within an inclusive range.
The bigint counterpart of between; see greaterThanBigInt.
Example
import {
assertEqual,
assertErr,
assertOk,
assertType,
BigInt,
betweenBigInt,
type Brand,
} from "@evolu/common";
const SignedByte = betweenBigInt(-128n, 127n)(BigInt);
assertType<typeof SignedByte.Output, bigint & Brand<"Between-128n-127n">>();
assertOk(SignedByte.fromUnknown(-128n), -128n);
assertOk(SignedByte.fromUnknown(127n), 127n);
const tooLarge = SignedByte.fromUnknown(128n);
assertErr(tooLarge, {
type: "Between-128n-127n",
value: 128n,
min: -128n,
max: 127n,
});
assertEqual(
SignedByte.formatError(tooLarge.error),
"The value 128 must be between -128 and 127, inclusive.",
);