# @typescript-eslint/no-duplicate-type-constituents

> Disallow the same type twice in a union or intersection

`string | number | string` means the same as `string | number`. The repeat adds nothing, and in a long union it hides what the type really allows.

The rule compares types, not only text, so it also finds an alias for a type that's already in the union. It also reports `| undefined` on an optional parameter, where the `?` already says it.

`--fix` removes the repeated type.

`bun lint --type-aware` turns this rule on in TypeScript files.

{/* Generated by src/codegen/lint-rule-docs.ts. Do not edit this section. */}

## Configure

Off by default. This rule needs types, so turning it on makes `bun lint` type check your code first.

```toml bunfig.toml
[lint.rules]
"@typescript-eslint/no-duplicate-type-constituents" = "error" # or "warn"
```

Every option, set to its default:

```toml bunfig.toml
[lint.rules]
"@typescript-eslint/no-duplicate-type-constituents" = ["error", {
  ignoreUnions = false,
  ignoreIntersections = false,
}]
```

{/* End of the generated section. */}

## Examples

Reported:

{/* bad {"count": 4} */}
```ts
type Id = string | number | string;

type Name = string;
type Label = Name | string;

type Point = { x: number } & { x: number };

function greet(name?: string | undefined) {}
```

Not reported:

{/* good */}
```ts
type Id = string | number;

type Point = { x: number } & { y: number };

function greet(name?: string) {}

interface User {
  nickname?: string | undefined;
}
```

## Options

| Option | Default | What it does |
| --- | --- | --- |
| `ignoreUnions` | `false` | Don't check `\|` unions. This also allows `\| undefined` on an optional parameter. |
| `ignoreIntersections` | `false` | Don't check `&` intersections. |

{/* good {"options": [{"ignoreUnions": true}]} */}
```ts
type Id = string | number | string;

function greet(name?: string | undefined) {}
```
