typescript/no-redundant-undefined-let
Disallow redundant undefined in let type unions when declarations are never
reassigned and initialized with definitely-defined values.
Targeted pattern scope
This rule targets let declarations that are:
- initialized with a syntactically definitely-defined value (for example
string, number, object, array, template literal, function, class, or
newvalue), - explicitly typed as a union including
undefined, and - never reassigned after declaration.
What this rule reports
This rule reports declarations such as:
let value: string | undefined = "x";
when the variable is never reassigned and initializer is definitely defined.
In those cases, | undefined is redundant.
Why this rule exists
When let is used for values that are never reassigned and initialized with
definite values, retaining | undefined adds type noise and weakens type
precision.
❌ Incorrect
let value: string | undefined = "x";
let count: number | undefined = 1 as const;
✅ Correct
let value: string = "x";
let count: number = 1 as const;
Behavior and migration notes
This rule is autofixable and also provides suggestions.
The fixer removes undefined from the top-level let type union while
preserving remaining union members.
To avoid unsafe assumptions, this rule does not report cases where:
- the initializer might evaluate to
undefined, or - the variable is reassigned later.
Options
This rule has no options.
Additional examples
let value: string | undefined = "x";
value = "y";
// ✅ valid (reassigned)
const maybe = undefined as string | undefined;
let output: string | undefined = maybe;
// ✅ valid (initializer may be undefined)
ESLint flat config example
import etcMisc from "eslint-plugin-etc-misc";
export default [
{
plugins: { "etc-misc": etcMisc },
rules: {
"etc-misc/typescript/no-redundant-undefined-let": "warn",
},
},
];
When not to use it
Disable this rule if your team intentionally keeps explicit | undefined in
never-reassigned let annotations for stylistic consistency.
Package documentation
Rule catalog ID: R094
Further reading
Adoption resources
- Start at warning level in CI, then move to error after cleanup.
- Use focused codemods/autofix batches per package or directory.