persona-community-5/.pnpm-store/v3/files/4f/c3ca562172397cddb3c9d4260b92552ed2f7c6685163f297194fe220e86ae5dcae63d2424cbb549f44b03372ba079ff9d896b32b722d9ad9f84d3f169f78c3
rdev-worker a1d0d1bf1c
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
build: /implement-feature community-ui --requirements 'Build the React commu...
2026-02-24 08:22:30 +00:00

61 lines
926 B
Plaintext

---
description: 'Require unary negation to take a number.'
---
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
> 🛑 This file is source code, not the primary documentation location! 🛑
>
> See **https://typescript-eslint.io/rules/no-unsafe-unary-minus** for documentation.
TypeScript does not prevent you from putting a minus sign before things other than numbers:
```ts
const s = 'hello';
const x = -s; // x is NaN
```
This rule restricts the unary `-` operator to `number | bigint`.
## Examples
<Tabs>
<TabItem value="❌ Incorrect">
```ts
declare const a: string;
-a;
declare const b: {};
-b;
```
</TabItem>
<TabItem value="✅ Correct">
```ts
-42;
-42n;
declare const a: number;
-a;
declare const b: number;
-b;
declare const c: number | bigint;
-c;
declare const d: any;
-d;
declare const e: 1 | 2;
-e;
```
</TabItem>
</Tabs>
{/* Intentionally Omitted: When Not To Use It */}