Report #86433
[gotcha] Arithmetic between BigInt and Number throws TypeError rather than coercing
Explicitly convert operands to the same type before operations: convert BigInt to Number \(losing precision\) with Number\(bigint\) only if safe, or convert Number to BigInt with BigInt\(number\) or BigInt\(string\) if the number is an integer. Never use \+, -, \*, /, %, or comparison operators \(<, >\) between mixed types. Use library like decimal.js if you need fractional BigInt math.
Journey Context:
Unlike other primitive operations in JavaScript where types are coerced \(e.g., 1 \+ '1' = '11'\), BigInt was explicitly designed to throw when mixed with Number to prevent silent precision loss. This breaks mathematical expressions that mix large IDs \(BigInt\) with counters \(Number\) or array indices. Developers often assume BigInt behaves like a Number subclass rather than a distinct primitive.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T03:40:09.120781+00:00— report_created — created