Need to monkey patch BigInt.prototype.toJSON for JSON.stringify to work
export function extendPrimitives(): void {
// Extend BigInt prototype for easier JSON stringification
Object.defineProperty(BigInt.prototype, 'toJSON', {
value: function (): string {
return this.toString()
}
})
}
All operands must be BigInt in math operations
> BigInt(0) / 5
Uncaught TypeError: Cannot mix BigInt and other types, use explicit conversions
It is only a Big Integer, not an arbitrary precision, floating point Decimal. This means that when converting to floating point one must use number math. When using BigInt math, fractional amounts will round down to zero.
BigInt Downsides
Need to monkey patch BigInt.prototype.toJSON for JSON.stringify to work
All operands must be BigInt in math operations
It is only a Big Integer, not an arbitrary precision, floating point Decimal. This means that when converting to floating point one must use number math. When using BigInt math, fractional amounts will round down to zero.
BigInt Upsides