Package: effect
Module: BigInt
Converts a number to a bigint.
When to use
Use to convert a JavaScript number to bigint only when it is a safe integer.
Details
If the number is outside the safe integer range for JavaScript
(Number.MAX_SAFE_INTEGER and Number.MIN_SAFE_INTEGER) or if the number is
not a valid bigint, it returns Option.none().
Example (Converting numbers to bigints)
import { BigInt } from "effect"
BigInt.fromNumber(42) // Option.some(42n)
BigInt.fromNumber(Number.MAX_SAFE_INTEGER + 1) // Option.none()
BigInt.fromNumber(Number.MIN_SAFE_INTEGER - 1) // Option.none()
See
toNumber for converting bigint values back to safe integer numbersBigInt for native constructor coercionSignature
declare const fromNumber: (n: number) => Option.Option<bigint>
Since v2.4.12