Skip to main content

isBigint()

isBigint(value): value is bigint

Checks if a value is a bigint.


Parameters​

value: unknown​

The value to check.


Returns: value is bigint​

true if the value is a bigint, false otherwise.


Since​

1.0.0


Example​

isBigint(123n);  // => true
isBigint(123); // => false
isBigint('123'); // => false

How it works?​

Type guard that checks if a value is a bigint.

Type Narrowing​

Common Checks​

ValueResult
123n true
BigInt(123) true
123 false
'123' false
new Object(123n) false

Use Cases​

Validate large number values πŸ“Œβ€‹

Validate BigInt values for precise calculations. Essential for handling large monetary values or IDs.

if (isBigInt(value)) {
return (value / 100n).toString(); // Safe BigInt operations
}

Handle API responses with mixed types πŸ“Œβ€‹

Handle responses that may contain BigInt values.

const id = isBigInt(response.id) 
? response.id.toString()
: String(response.id);

Type-safe arithmetic operations​

Ensure type safety before BigInt operations.

if (isBigInt(a) && isBigInt(b)) {
return a / b; // TypeScript knows both are bigint
}