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
123ncheckmark true
BigInt(123)checkmark true
123cross false
'123'cross false
new Object(123n)cross 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
}