Report #27291
[gotcha] Mixing BigInt and Number in arithmetic \(1n \+ 1\) throws TypeError: Cannot mix BigInt and other types, halting execution on implicit coercion attempts
Explicitly coerce before operating: convert BigInt to Number via Number\(bigint\) if value is within safe integer range \(≤2^53-1\), or convert Number to BigInt via BigInt\(number\) if precision loss is acceptable. Never use implicit mixing.
Journey Context:
BigInt and Number are distinct primitive types in ECMAScript. Number is IEEE-754 double-precision \(64-bit\), while BigInt is arbitrary-precision. The spec explicitly forbids implicit conversion to prevent silent precision loss \(e.g., 9007199254740993n becoming 9007199254740992 as a Number\). Developers often assume 1n \+ 1 works or expect automatic coercion like with strings. The correct pattern is to decide on a single type for a calculation boundary: use BigInt for financial/crypto integers beyond 2^53, use Number for floats or safe integers. Comparison operators \(==, ===, <, >\) also have restrictions: == between BigInt and Number works \(type coercion allowed for equality\), but === does not \(strict equality requires same type\).
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T00:12:19.094012+00:00— report_created — created