sindresorhus/is · error · TypeError
Expected value which is `bigint`, received value of type `${
Error message
Expected value which is `bigint`, received value of type `${is(value)}`. What it means
Thrown by `assertBigint(value)` when `typeof value !== 'bigint'`. The library treats `number` and `bigint` as strictly distinct primitives, so a regular number — even an integer like `42` — fails, as do numeric strings and `BigInt` object wrappers created with `Object(1n)`.
Source
Thrown at source/index.ts:1486
throw new TypeError(message ?? typeErrorMessage('AsyncGenerator', value));
}
}
export function assertAsyncGeneratorFunction(value: unknown, message?: string): asserts value is AsyncGeneratorFunction {
if (!isAsyncGeneratorFunction(value)) {
throw new TypeError(message ?? typeErrorMessage('AsyncGeneratorFunction', value));
}
}
export function assertAsyncIterable<T = unknown>(value: unknown, message?: string): asserts value is AsyncIterable<T> {
if (!isAsyncIterable(value)) {
throw new TypeError(message ?? typeErrorMessage('AsyncIterable', value));
}
}
export function assertBigint(value: unknown, message?: string): asserts value is bigint {
if (!isBigint(value)) {
throw new TypeError(message ?? typeErrorMessage('bigint', value));
}
}
export function assertBigInt64Array(value: unknown, message?: string): asserts value is BigInt64Array {
if (!isBigInt64Array(value)) {
throw new TypeError(message ?? typeErrorMessage('BigInt64Array', value));
}
}
export function assertBigUint64Array(value: unknown, message?: string): asserts value is BigUint64Array {
if (!isBigUint64Array(value)) {
throw new TypeError(message ?? typeErrorMessage('BigUint64Array', value));
}
}
export function assertBlob(value: unknown, message?: string): asserts value is Blob {
if (!isBlob(value)) {
throw new TypeError(message ?? typeErrorMessage('Blob', value));View on GitHub ↗ (pinned to 7821031c66)
Solutions
- Convert at the boundary: `BigInt(value)` for integer numbers or well-formed numeric strings (wrap in try/catch — `BigInt('abc')` and `BigInt(1.5)` throw).
- Use a JSON reviver or the driver's bigint mode (e.g. pg/mysql2 `supportBigNumbers`/`bigNumberStrings` options) so 64-bit values arrive as bigints or exact strings.
- Write bigint literals with the `n` suffix (`42n`) instead of plain numbers.
- If both number and bigint are acceptable, assert with `assert.any([is.number, is.bigint], value)` instead.
Example fix
// before const id = JSON.parse(body).id; // number or string assert.bigint(id); // throws // after const id = BigInt(JSON.parse(body).id); assert.bigint(id);
Defensive patterns
Strategy: type-guard
Validate before calling
if (typeof value !== 'bigint') {
// convert deliberately: BigInt(value) for safe integers, or reject
} Type guard
const isBigInt = (value) => typeof value === 'bigint';
Try / catch
try {
assert.bigint(value);
} catch (error) {
if (error instanceof TypeError) { /* got number or numeric string */ }
else { throw error; }
} Prevention
- JSON has no bigint — deserialized payloads arrive as number or string; convert with BigInt() at the boundary
- Numeric literals need the n suffix (123n); 123 is a number and fails
- Guard BigInt(x) conversion itself in try/catch — non-integer numbers and bad strings throw
When it happens
Trigger: Passing a plain number (`assert.bigint(42)`), a numeric string from JSON or an env var, or `null`/`undefined` to code requiring `bigint`. JSON.parse never produces bigints, so any value deserialized from JSON fails this assertion unless explicitly converted.
Common situations: IDs or balances serialized through JSON (bigints can't survive `JSON.stringify`/`parse`, so they arrive as strings or numbers); database drivers returning 64-bit columns as strings; blockchain/crypto amounts handled as numbers upstream; environment variables which are always strings.
Related errors
- Expected value which is `BigInt64Array`, received value of t
- Expected value which is `BigUint64Array`, received value of
- Expected value which is `Date`, received value of type `${is
- Expected value which is `Map`, received value of type `${is(
- Expected value which is `Set`, received value of type `${is(
AI-assisted analysis of sindresorhus/is@7821031c66 (2026-07-31).
Data as JSON: /data/errors/f2f6f80d8516b1a3.json.
Report an issue: GitHub ↗.