eslint-plugin-redundant-undefined
raw JSON → 1.0.0 verified Sat Apr 25 auth: no javascript
An ESLint plugin (v1.0.0, single release so far) that forbids redundant `undefined` in TypeScript optional parameters and properties. It helps enforce cleaner optional types by flagging patterns like `s?: string | undefined` and offering a `followExactOptionalPropertyTypes` option for use with TypeScript's `exactOptionalPropertyTypes` setting. Requires `@typescript-eslint/parser` and ESLint >=8.46.0. Available on npm with MIT license.
Common errors
error Error: Failed to load plugin 'redundant-undefined': Cannot find module 'eslint-plugin-redundant-undefined' ↓
cause Plugin not installed or missing from node_modules.
fix
Run
npm install eslint-plugin-redundant-undefined @typescript-eslint/parser --save-dev error Parsing error: 'parserOptions.project' has been set for @typescript-eslint/parser. The file does not match your project config: .eslintrc.json ↓
cause ESLint is trying to parse the config file itself with TypeScript parser.
fix
Add
'ignorePatterns': ['.eslintrc.json'] to your ESLint config or use a .eslintrc.js file. error Error: Rule 'redundant-undefined' (or 'redundant-undefined/redundant-undefined') is not defined ↓
cause Plugin not listed in 'plugins' array or rule name misspelled.
fix
Add 'redundant-undefined' to plugins and use 'redundant-undefined/redundant-undefined' as rule name.
Warnings
gotcha Rule only works with `@typescript-eslint/parser`; using default ESLint parser will cause parsing errors. ↓
fix Set parser to '@typescript-eslint/parser' in ESLint config.
gotcha The rule name is 'redundant-undefined/redundant-undefined' – users often try 'redundant-undefined' alone or forget the slash. ↓
fix Use the full prefixed name: 'redundant-undefined/redundant-undefined'.
gotcha Plugin requires ESLint >=8.46.0 and Node.js ^16.0.0 or >=18.0.0; older versions will fail to load. ↓
fix Update ESLint and Node.js to supported versions.
gotcha Option `followExactOptionalPropertyTypes` changes the rule behavior; enabling it without having `exactOptionalPropertyTypes: true` in tsconfig may cause unexpected lint errors. ↓
fix Ensure TypeScript's `exactOptionalPropertyTypes` is enabled if using this option.
Install
npm install eslint-plugin-redundant-undefined yarn add eslint-plugin-redundant-undefined pnpm add eslint-plugin-redundant-undefined Imports
- redundant-undefined wrong
require('eslint-plugin-redundant-undefined') or import syntax in config is not supportedcorrect// In .eslintrc: { "plugins": ["redundant-undefined"], "rules": { "redundant-undefined/redundant-undefined": "error" } } - default rule wrong
Setting 'redundant-undefined' as a top-level rule like 'redundant-undefined': 'error' (missing slash) or using wrong rule namecorrectrules: { "redundant-undefined/redundant-undefined": "error" }
Quickstart
// .eslintrc.json
{
"parser": "@typescript-eslint/parser",
"plugins": ["redundant-undefined"],
"rules": {
"redundant-undefined/redundant-undefined": "error"
}
}
// Install
// npm i eslint-plugin-redundant-undefined @typescript-eslint/parser eslint --save-dev
// Example code that will be flagged:
// function f(s?: string | undefined): void {}