noUnsafeUnaryMinus (JavaScript)
Language JavaScript (and super languages)
Summary
Section titled “Summary”- Rule available since:
v2.6.0 - Diagnostic Category:
lint/nursery/noUnsafeUnaryMinus - 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": { "noUnsafeUnaryMinus": "error" } } }}Description
Section titled “Description”Require the operand of unary - to be a number or a bigint.
Unary negation converts any other operand to a number first. Negating a
string, boolean, nullish value, or object usually produces NaN or an
unexpected number, and TypeScript accepts many of these cases without
reporting an error.
Operands typed as any or never are allowed. Explicit unknown
operands are reported.
Examples
Section titled “Examples”Invalid
Section titled “Invalid”declare const value: string;-value;/invalid-string.ts:2:1 lint/nursery/noUnsafeUnaryMinus ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ The operand of unary - may be string instead of number or bigint.
1 │ declare const value: string;
> 2 │ -value;
│ ^^^^^^
3 │
ℹ Unary - converts other values to a number first, which usually produces NaN or an unexpected result.
ℹ Convert the operand to a number explicitly, or negate a numeric value instead.
ℹ 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 const value: { x: number };-value;/invalid-object.ts:2:1 lint/nursery/noUnsafeUnaryMinus ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ The operand of unary - may be object instead of number or bigint.
1 │ declare const value: { x: number };
> 2 │ -value;
│ ^^^^^^
3 │
ℹ Unary - converts other values to a number first, which usually produces NaN or an unexpected result.
ℹ Convert the operand to a number explicitly, or negate a numeric value instead.
ℹ 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 const value: unknown;-value;/invalid-unknown.ts:2:1 lint/nursery/noUnsafeUnaryMinus ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ The operand of unary - may be unknown instead of number or bigint.
1 │ declare const value: unknown;
> 2 │ -value;
│ ^^^^^^
3 │
ℹ Unary - converts other values to a number first, which usually produces NaN or an unexpected result.
ℹ Convert the operand to a number explicitly, or negate a numeric value instead.
ℹ 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 const value: number;-value;declare const value: number | bigint;-value;declare const value: { x: number };-value.x;Related links
Section titled “Related links”Copyright (c) 2023-present Biome Developers and Contributors.