prefer-bigint-literals
UnreleasedConfiguration
rslint.config.ts
Rule details
Prefer a bigint literal when the argument to the built-in BigInt() function
is an integer number or a string that can be converted to a bigint. The rule
checks quoted strings, templates without substitutions, and numeric literals
with unary + or -.
Examples of incorrect code for this rule
Examples of correct code for this rule
The rule offers editor suggestions for calls that contain comments or an
explicit + sign. It also offers a suggestion when a numeric argument needs a
different spelling as a bigint literal, as in BigInt(1e2) becoming 100n.
Options
This rule has no options.
Differences from upstream
- Rslint skips calls where a local binding or a
withstatement can supply anotherBigIntfunction. It also skips calls with TypeScript type arguments or whenlanguageOptions.globalsdisablesBigInt. - Keep the call when the configured ECMAScript version predates ES2020. Rslint also skips TypeScript files with a build target older than ES2020.
BigInt(1000000000000000100)suggests1000000000000000128nto preserve the value of the call after JavaScript rounds the numeric argument.- Fixes add spaces where compact code would otherwise run together. For example,
BigInt(1)in objectbecomes1n in object. - Rslint rejects the legacy spellings in
BigInt(0777)andBigInt(0888)even in scripts. Write511nand888nfor those values.