@typescript-eslint/no-loss-of-precision
Disallow number literals that cannot be stored exactly as written
deprecated
Also called typescript-eslint/no-loss-of-precision, typescript/no-loss-of-precision
A JavaScript number holds 15 to 17 significant digits. A literal that needs more is rounded without a warning, so the program runs with a different number than the one in the source. This often happens with IDs copied from a database.
Use a bigint or a string for a large integer.
This rule is deprecated. Use no-loss-of-precision instead.
Examples#
example.ts2 problems
const orderId = 9007199254740993This number literal will lose precision at runtime.; // stored as 9007199254740992
const limit = 2e999This number literal will lose precision at runtime.; // stored as Infinityexample.tsNo problems
const orderId = 9007199254740993n;
const invoiceId = "9007199254740993";
const rate = 0.3;
const limit = Number.MAX_VALUE;