Перейти до вмісту

noUnsafePlusOperands

Цей контент ще не доступний вашою мовою.

biome.json
{
"linter": {
"rules": {
"nursery": {
"noUnsafePlusOperands": "error"
}
}
}
}

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.

invalid-bigint-plus-number.ts
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.

invalid-number-plus-bigint.ts
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.

invalid-bigint-add-assign.ts
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.

valid-number-plus-number.ts
const sum = 1 + 2;
valid-string-plus-number.ts
const message = "value: " + 1;
valid-bigint-add-assign.ts
let total = 1n;
total += 2n;