noUnsafePlusOperands
このコンテンツはまだ日本語訳がありません。
Summary
Section titled “Summary”- Rule available since:
v2.4.10 - Diagnostic Category:
lint/nursery/noUnsafePlusOperands - This rule doesn’t have a fix.
- The default severity of this rule is information.
- This rule belongs to the following domains:
- Sources:
How to configure
Section titled “How to configure”{ "linter": { "rules": { "nursery": { "noUnsafePlusOperands": "error" } } }}Description
Section titled “Description”Disallow + operations with operands that are known to be unsafe.
This rule uses type information to report + and += operations that are
very likely mistakes at runtime, such as mixing number with bigint or
using object-like, symbol, unknown, or never values as operands.
This port intentionally does not support the original rule’s options.
It keeps the upstream default behavior for no-option usage and always checks
compound += assignments.
Examples
Section titled “Examples”Invalid
Section titled “Invalid”const value = 1n + 1;/invalid-bigint-plus-number.ts:1:15 lint/nursery/noUnsafePlusOperands ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ Numeric + operations must use either two bigint values or two number values.
> 1 │ const value = 1n + 1;
│ ^^^^^^
2 │
ℹ This operation mixes number with bigint.
> 1 │ const value = 1n + 1;
│ ^^^^^^
2 │
ℹ Convert one side so both operands use the same numeric type before applying + or +=.
ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.
const value = 1 + 1n;/invalid-number-plus-bigint.ts:1:15 lint/nursery/noUnsafePlusOperands ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ Numeric + operations must use either two bigint values or two number values.
> 1 │ const value = 1 + 1n;
│ ^^^^^^
2 │
ℹ This operation mixes number with bigint.
> 1 │ const value = 1 + 1n;
│ ^^^^^^
2 │
ℹ Convert one side so both operands use the same numeric type before applying + or +=.
ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.
declare let count: number;count += 1n;/invalid-bigint-add-assign.ts:2:1 lint/nursery/noUnsafePlusOperands ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ Numeric + operations must use either two bigint values or two number values.
1 │ declare let count: number;
> 2 │ count += 1n;
│ ^^^^^^^^^^^
3 │
ℹ This operation mixes number with bigint.
1 │ declare let count: number;
> 2 │ count += 1n;
│ ^^^^^^^^^^^
3 │
ℹ Convert one side so both operands use the same numeric type before applying + or +=.
ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.
const sum = 1 + 2;const message = "value: " + 1;let total = 1n;total += 2n;Related links
Section titled “Related links”Copyright (c) 2023-present Biome Developers and Contributors.