> For AI agents: the complete documentation index is available at https://rslint.rs/llms.txt, the full documentation bundle is available at https://rslint.rs/llms-full.txt.

# restrict-plus-operands

[Added in v0.1.4](https://github.com/web-infra-dev/rslint/releases/tag/v0.1.4)
## Configuration

| Preset                              | Configured Value                                                                                                          |
| ----------------------------------- | ------------------------------------------------------------------------------------------------------------------------- |
| ✅ ts.configs.recommendedTypeChecked | `"error"`                                                                                                                 |
| ✅ ts.configs.strictTypeChecked      | `["error",{"allowAny":false,"allowBoolean":false,"allowNullish":false,"allowNumberAndString":false,"allowRegExp":false}]` |


```ts title=rslint.config.ts
import { defineConfig, ts } from '@rslint/core';

export default defineConfig([
  ts.configs.recommended,
  {
    rules: {
      '@typescript-eslint/restrict-plus-operands': 'error',
    },
  },
]);
```

## Rule Details

Require both operands of addition to be the same type and be `bigint`, `number`, or `string`. The `+` operator in TypeScript can be used for both addition and string concatenation. This rule ensures that operands of `+` are both numbers, both bigints, or both strings, preventing accidental implicit type coercions that can lead to unexpected results (e.g., `"1" + 2` becoming `"12"` instead of `3`).

Examples of **incorrect** code for this rule:

```typescript
const result = 1 + '2';
const bad = 1n + 2;
const invalid = {} + [];
```

Examples of **correct** code for this rule:

```typescript
const sum = 1 + 2;
const concat = 'a' + 'b';
const bigSum = 1n + 2n;
const explicit = String(1) + '2';
```

## Original Documentation

- [typescript-eslint: restrict-plus-operands](https://typescript-eslint.io/rules/restrict-plus-operands)
- [Source code](https://github.com/typescript-eslint/typescript-eslint/blob/v8.67.0/packages/eslint-plugin/src/rules/restrict-plus-operands.ts)
