{"id":"f2f6f80d8516b1a3","repo":"sindresorhus/is","slug":"expected-value-which-is-bigint-received-value-o","errorCode":null,"errorMessage":"Expected value which is `bigint`, received value of type `${is(value)}`.","messagePattern":"Expected value which is `bigint`, received value of type `(.+?)`\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"source/index.ts","lineNumber":1486,"sourceCode":"\t\tthrow new TypeError(message ?? typeErrorMessage('AsyncGenerator', value));\n\t}\n}\n\nexport function assertAsyncGeneratorFunction(value: unknown, message?: string): asserts value is AsyncGeneratorFunction {\n\tif (!isAsyncGeneratorFunction(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('AsyncGeneratorFunction', value));\n\t}\n}\n\nexport function assertAsyncIterable<T = unknown>(value: unknown, message?: string): asserts value is AsyncIterable<T> {\n\tif (!isAsyncIterable(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('AsyncIterable', value));\n\t}\n}\n\nexport function assertBigint(value: unknown, message?: string): asserts value is bigint {\n\tif (!isBigint(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('bigint', value));\n\t}\n}\n\nexport function assertBigInt64Array(value: unknown, message?: string): asserts value is BigInt64Array {\n\tif (!isBigInt64Array(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('BigInt64Array', value));\n\t}\n}\n\nexport function assertBigUint64Array(value: unknown, message?: string): asserts value is BigUint64Array {\n\tif (!isBigUint64Array(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('BigUint64Array', value));\n\t}\n}\n\nexport function assertBlob(value: unknown, message?: string): asserts value is Blob {\n\tif (!isBlob(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('Blob', value));","sourceCodeStart":1468,"sourceCodeEnd":1504,"githubUrl":"https://github.com/sindresorhus/is/blob/7821031c66cdeb7256a0feb2d506535f9e84fcaf/source/index.ts#L1468-L1504","documentation":"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)`.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nconst id = JSON.parse(body).id; // number or string\nassert.bigint(id); // throws\n// after\nconst id = BigInt(JSON.parse(body).id);\nassert.bigint(id);","handlingStrategy":"type-guard","validationCode":"if (typeof value !== 'bigint') {\n  // convert deliberately: BigInt(value) for safe integers, or reject\n}","typeGuard":"const isBigInt = (value) => typeof value === 'bigint';","tryCatchPattern":"try {\n  assert.bigint(value);\n} catch (error) {\n  if (error instanceof TypeError) { /* got number or numeric string */ }\n  else { throw error; }\n}","preventionTips":["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"],"tags":["type-assertion","bigint","serialization"],"analyzedSha":"7821031c66cdeb7256a0feb2d506535f9e84fcaf","analyzedAt":"2026-07-31T18:34:06.268Z","schemaVersion":2}