ESlint rule for disallow redundant undefined
npm install eslint-plugin-redundant-undefined> Forbids optional parameters to include an explicit undefined in their type and requires to use undefined in optional properties.
  !GitHub Workflow Status (with branch)  
```
$ npm i eslint-plugin-redundant-undefined @typescript-eslint/parser --save-dev
Add redundant-undefined to the plugins section of your .eslintrc configuration file. You can omit the eslint-plugin- prefix:
`json`
{
"parser": "@typescript-eslint/parser",
"plugins": ["redundant-undefined"]
}
Then configure the rules you want to use under the rules section.
`json`
{
"rules": {
"redundant-undefined/redundant-undefined": "error"
}
}
- Avoid explicitly specifying undefined as a type for a parameter/property which is already optional
- followExactOptionalPropertyTypes - Requires explicitly specifying undefined as a type for a parameter which is already optional., this provides the correct semantics for people who have exactOptionalPropertyType: true
Examples of incorrect code:
`ts
function f(s?: undefined | string): void {}
function f(s?: number | undefined | string): void {}
interface I {
a?: string | undefined;
}
class C {
a?: string | undedined;
}
`
Examples of correct code:
`ts
function f(s?: string): void {}
interface I {
a?: string;
}
interface I {
a?: any;
}
class C {
a?: string;
}
`
Examples of incorrect code for the { "followExactOptionalPropertyTypes": true }:
`ts
interface I {
p?: string;
}
class C {
private p?: number;
}
abstract class C {
abstract p?: string;
}
`
Examples of correct code for the { "followExactOptionalPropertyTypes": true }:
`ts
interface I {
p?: string | undefined;
}
interface I {
p?: any;
}
class C {
private p?: number | undefined;
}
abstract class C {
abstract p?: string | undefined;
}
``
This software is released under the terms of the MIT license.