Large integer values
Representing integer identifiers or counters that can exceed JavaScript number precision.
TypeScript · Type Alias
bigint is TypeScript’s primitive type for arbitrarily large integers. Values come from BigInt() or integer literals with an n suffix, and bigint arithmetic cannot mix with number operands.
bigint is TypeScript’s primitive type for arbitrarily large integers. Create values with the BigInt() function or an integer literal ending in n; arithmetic requires bigint operands rather than mixing them with number values.
let value: bigint = BigInt(100);
let literal: bigint = 100n;bigint is a distinct primitive type, written in lowercase, rather than the BigInt constructor name.BigInt() or with an integer literal using the n suffix.n directly to an integer numeric literal, such as 100n.typeof value === "bigint" check can narrow a value to the bigint type.bigint when integer values may exceed the safe precision range of ordinary JavaScript numbers.number and bigint operands in arithmetic; convert explicitly first.esnext compilation target for BigInt support.const accountId: bigint = 9007199254740993n;
const fromText: bigint = BigInt("9007199254740993");
function add(a: bigint, b: bigint): bigint {
return a + b;
}
console.log(add(accountId, fromText));This runnable example declares bigint values using both supported creation forms and adds two bigint operands.
Representing integer identifiers or counters that can exceed JavaScript number precision.
Performing exact integer arithmetic without floating-point rounding at large magnitudes.
Using runtime type guards for values whose type may be bigint.
BigInt()numbertypeofesnextesnext.bigint