Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Zod · Module

z.bigint

z.bigint() creates a Zod schema for validating JavaScript bigint values. It supports comparison, sign, and divisibility constraints.

How it works

z.bigint() creates a schema that accepts JavaScript bigint values. Chain bigint-specific checks such as comparisons, sign constraints, and divisibility; use z.coerce.bigint() instead when the input must first be converted to bigint.

Syntax

z.bigint()

Returns

A Zod bigint schema.

Key points

  • Call z.bigint() to create a schema whose input type is JavaScript bigint.
  • The schema supports specialized constraints for ordering, sign, and divisibility.
  • positive() requires a value above zero; the documentation identifies gt(0n) as its alias.

Common mistakes

  • z.bigint() validates bigint inputs; it does not perform the coercion described by the documentation. Choose z.coerce.bigint() when conversion is required.

Example: Validate a constrained bigint

import { z } from "zod";

const schema = z.bigint().positive().multipleOf(5n);

console.log(schema.parse(25n)); // 25n
// schema.parse(22n); // throws: not a multiple of 5

Validates a positive bigint divisible by 5.

When to use it

Big integer input validation

Validate IDs, counters, timestamps, or other values represented as JavaScript bigint.

Domain constraints

Enforce a minimum, maximum, sign, or divisibility rule on a bigint.

Coerced bigint parsing

Accept coercible external input when conversion to bigint is desired.

Interview questions

QWhat does z.bigint() validate?

z.bigint() is a Zod schema for validating JavaScript bigint values. It can be refined with bigint-specific checks such as gt, positive, and multipleOf.

Follow-up: How would you accept a string such as "123"? Use z.coerce.bigint(), or build a codec when an explicit bidirectional conversion is needed.

QHow do bigint comparison constraints work?

gte(5n) requires a value greater than or equal to 5n; the documentation lists .min(5n) as its alias. Similarly, lte(5n) is the alias-bearing upper-bound check corresponding to .max(5n).

Follow-up: How would you require a strict lower bound? Use gt(5n) rather than gte(5n).

QWhich specialized validations are available?

Use positive() or nonnegative() for sign requirements, and negative() or nonpositive() for negative-side requirements. For divisibility, use multipleOf(5n); the documentation lists .step(5n) as its alias.

Follow-up: How could you combine sign and divisibility constraints? Chain both methods, such as z.bigint().positive().multipleOf(5n).

  • z.coerce.bigint
  • z.codec
  • z.int

Source: Defining schemas | Zod. Checked 2026-10-15.