consistent-optional-props
Disallow redundant undefined unions on optional properties.
Targeted pattern scopeโ
This rule targets optional properties that redundantly include undefined in
their union type.
Covered nodes include:
- interface/type property signatures (
TSPropertySignature), and - class property definitions (
PropertyDefinition).
What this rule reportsโ
This rule reports ? properties whose type union explicitly includes
undefined.
Example pattern:
name?: string | undefined;
Because ? already implies undefined, the explicit union member is redundant.
Why this rule existsโ
Removing redundant undefined unions keeps type declarations smaller and easier
to read.
โ Incorrectโ
interface User {
name?: string | undefined;
}
class Config {
timeoutMs?: number | undefined;
}
โ Correctโ
interface User {
name?: string;
}
class Config {
timeoutMs?: number;
}
Behavior and migration notesโ
This rule reports only and does not provide an autofix.
Migration is straightforward: remove | undefined from optional properties.
Optionsโ
This rule has no options.
Additional examplesโ
type Options = {
verbose?: boolean | undefined;
};
// โ reported
type OptionsFixed = {
verbose?: boolean;
};
// โ
valid
ESLint flat config exampleโ
import etcMisc from "eslint-plugin-etc-misc";
export default [
{
plugins: { "etc-misc": etcMisc },
rules: {
"etc-misc/consistent-optional-props": "error",
},
},
];
When not to use itโ
Disable this rule if your codebase intentionally keeps explicit
| undefined unions for documentation style.
Package documentationโ
Rule catalog ID: R008
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.