noPrecisionLoss
诊断类别:lint/correctness/noPrecisionLoss
¥Diagnostic Category: lint/correctness/noPrecisionLoss
自从:v1.0.0
¥Since: v1.0.0
来源:
¥Sources:
-
与以下相同:
no-loss-of-precision
¥Same as:
no-loss-of-precision
-
与以下相同:
@typescript-eslint/no-loss-of-precision
¥Same as:
@typescript-eslint/no-loss-of-precision
-
与以下相同:
lossy_float_literal
¥Same as:
lossy_float_literal
禁止丢失精度的文字数字
¥Disallow literal numbers that lose precision
¥Examples
¥Invalid
code-block.js:1:11 lint/correctness/noPrecisionLoss ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ This number literal will lose precision at runtime.
> 1 │ const x = 9007199254740993
│ ^^^^^^^^^^^^^^^^
2 │
ℹ The value at runtime will be 9007199254740992
code-block.js:1:11 lint/correctness/noPrecisionLoss ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ This number literal will lose precision at runtime.
> 1 │ const x = 5.123000000000000000000000000001
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2 │
ℹ The value at runtime will be 5.123
code-block.js:1:11 lint/correctness/noPrecisionLoss ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ This number literal will lose precision at runtime.
> 1 │ const x = 0x20000000000001
│ ^^^^^^^^^^^^^^^^
2 │
ℹ The value at runtime will be 9007199254740992
code-block.js:1:11 lint/correctness/noPrecisionLoss ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ This number literal will lose precision at runtime.
> 1 │ const x = 0x2_000000000_0001;
│ ^^^^^^^^^^^^^^^^^^
2 │
ℹ The value at runtime will be 9007199254740992
¥Valid
¥Related links