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โ
| Value | Result |
|---|---|
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
}
true
false