Skip to main content

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.