TypeError: can't convert BigInt to number
TypeError: Cannot mix BigInt and other types, use explicit conversions (V8-based) TypeError: BigInts have no unsigned right shift, use >> instead (V8-based) TypeError: can't convert BigInt to number (Firefox) TypeError: Invalid mix of BigInt and other type in addition/multiplication/…. (Safari) TypeError: BigInt does not support >>> operator (Safari)
The two sides of an arithmetic operator must both be BigInts or both not. If an operation involves a mix of BigInts and numbers, it's ambiguous whether the result should be a BigInt or number, since there may be loss of precision in both cases.
The error can also happen if the unsigned right shift operator (
>>>) is used between two BigInts. In Firefox, the message is the same: "can't convert BigInt to number".
const sum = 1n + 1; // TypeError: can't convert BigInt to number
Instead, explicitly coerce one side to a BigInt or number.
const sum = 1n + BigInt(1); const sum2 = Number(1n) + 1;
const a = 4n >>> 2n; // TypeError: can't convert BigInt to number
Use normal right shift instead.
const a = 4n >> 2n;