close

no-duplicate-type-constituents

Configuration

rslint.config.ts
import { defineConfig, ts } from '@rslint/core';

export default defineConfig([
  ts.configs.recommended,
  {
    rules: {
      '@typescript-eslint/no-duplicate-type-constituents': 'error',
    },
  },
]);

Rule Details

Disallows duplicate constituents in union or intersection types. Having the same type more than once in a union (|) or intersection (&) is redundant and can be removed without changing the type. This rule also flags explicit undefined on optional parameters, since the ? modifier already implies undefined.

Examples of incorrect code for this rule:

type Foo = string | string;

type Bar = number & number;

type Baz = 'a' | 'b' | 'a';

function fn(x?: string | undefined) {}

Examples of correct code for this rule:

type Foo = string | number;

type Bar = { a: string } & { b: number };

type Baz = 'a' | 'b' | 'c';

function fn(x?: string) {}

Original Documentation