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, and this page is available as Markdown at https://rslint.rs/rules/typescript-eslint/restrict-plus-operands.md.
close

restrict-plus-operands

Added in v0.1.4

Configuration

PresetConfigured Value
✅ ts.configs.recommendedTypeChecked"error"
✅ ts.configs.strictTypeChecked["error",{"allowAny":false,"allowBoolean":false,"allowNullish":false,"allowNumberAndString":false,"allowRegExp":false}]
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:

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

Examples of correct code for this rule:

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

Original Documentation