API reference › @evolu/common › Type › Int32
type Int32 = number &
Brand<"NonNaN"> &
Brand<"Finite"> &
Brand<"Int"> &
Brand<"Between-2147483648-2147483647"> &
Brand<"Int32">;
Defined in: packages/common/src/Type.ts:12326
Signed 32-bit Int.
Accepts integers from -2147483648 through 2147483647, inclusive, the range of
32-bit integers in Protocol Buffers, PostgreSQL integer, and JavaScript
bitwise operators. Like Int, it accepts -0. Int64 is the
signed 64-bit bigint counterpart.
Example
import { assertEqual, assertErr, assertOk, Int32 } from "@evolu/common";
assertOk(Int32.fromUnknown(-2147483648), -2147483648);
assertOk(Int32.fromUnknown(2147483647), 2147483647);
assertErr(Int32.fromUnknown(1.5), { type: "Int", value: 1.5 });
const tooLarge = Int32.fromUnknown(2147483648);
assertErr(tooLarge, {
type: "Between-2147483648-2147483647",
value: 2147483648,
min: -2147483648,
max: 2147483647,
});
assertEqual(
Int32.formatError(tooLarge.error),
"The value 2147483648 must be between -2147483648 and 2147483647, inclusive.",
);