# no-redundant-optional

Rule `sonarjs/no-redundant-optional`. Optional properties should not redundantly include 'undefined'

- Source: sonarjs
- Technologies: JavaScript
- Kind: style
- Needs type information: yes
- Autofix: yes, in at least one linter
- Reach: 6.2M weekly downloads of presets that enable it
- Trend: +62.1% last quarter
- Rank: #1309 by reach, #610 by growth

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `sonarjs/no-redundant-optional` | yes | suggestion | package `eslint-plugin-sonarjs` | [docs](https://rules.sonarsource.com/javascript/RSPEC-4782/) |

## Code examples

### Incorrect: the rule reports this

```js
interface Person {
  name: string;
  address? : string | undefined;   // Noncompliant, "?" should be removed
  pet?: Animal | undefined; // Noncompliant, "undefined" should be removed
}
```

### Correct: the rule accepts this

```js
interface Person {
  name: string;
  address: string | undefined;
  pet?: Animal;
}
```

Examples from the ESLint documentation.

## Enable it

### ESLint: `eslint.config.js`

```js
export default [
  {
    rules: {
      "sonarjs/no-redundant-optional": "error",
    },
  },
];
```

## Presets that enable it

| Preset | Linter | Package | Rules | Weekly downloads | Trend |
| --- | --- | --- | --- | --- | --- |
| [SonarJS recommended](https://lintradar.dev/presets/sonarjs-recommended.md) | ESLint | `eslint-plugin-sonarjs` | 230 | 6.2M | +62.1% |

## Related rules

- [sonarjs/no-redundant-jump](https://lintradar.dev/rules/sonarjs/no-redundant-jump.md): Jump statements should not be redundant
- [sonarjs/no-referrer-policy](https://lintradar.dev/rules/sonarjs/no-referrer-policy.md): HTTP Referrer-Policy should not be set to an unsafe value
- [sonarjs/no-redundant-boolean](https://lintradar.dev/rules/sonarjs/no-redundant-boolean.md): Boolean literals should not be used in comparisons
- [sonarjs/no-regex-spaces](https://lintradar.dev/rules/sonarjs/no-regex-spaces.md): Regular expressions should not contain multiple spaces
- [sonarjs/no-redundant-assignments](https://lintradar.dev/rules/sonarjs/no-redundant-assignments.md): Assignments should not be redundant
- [sonarjs/no-same-argument-assert](https://lintradar.dev/rules/sonarjs/no-same-argument-assert.md): Assertions should not be given twice the same argument

---

Web page: https://lintradar.dev/rules/sonarjs/no-redundant-optional. Data from npm and the linters' documentation, collected Dec 4, 2026. Site guide for agents: https://lintradar.dev/llms.txt
