Report #46005
[gotcha] Arithmetic between BigInt and Number throws TypeError instead of coercing
Explicitly convert operands to a common type using Number\(bigint\) or BigInt\(number\) before the operation, or normalize the codebase to use only BigInt for integer arithmetic to avoid mixed-type operations
Journey Context:
Unlike other primitive pairs \(e.g., string \+ number\), BigInt and Number exist in separate type namespaces and cannot be implicitly converted during arithmetic \(\+, -, \*, /, %\) or strict equality \(===\). Attempting 1n \+ 1 throws a TypeError to prevent silent loss of precision for integers above 2^53. Loose equality \(==\) does allow comparison \(0n == 0 is true\), but arithmetic is strictly forbidden. This creates friction when mixing timestamps \(Numbers from Date.now\(\)\) with nanosecond-precision BigInts. The fix requires explicit conversion, with careful attention to truncation when downcasting BigInt to Number.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T07:41:43.917118+00:00— report_created — created