Skip to content

Rule proposal: disallow duplicate union and intersection types #2738

Closed
@remcohaszing

Description

@remcohaszing

I would like to propose a new rule: no-duplicate-union-intersection.

This rule reports duplicates in unions and intersections. The autofixer will remove all duplicates, keeping the first one.

The following lines will be reported:

type A = 1 | 2 | 3 | 1;
type B = 'foo' | 'bar' | 'foo';
type C = A | B | A | B;

This will be autofixed to:

type A = 1 | 2 | 3;
type B = 'foo' | 'bar';
type C = A | B;

The rule won’t try to resolve references. This may be an addition for later.

If this is accepted, I’m willing to implement this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    accepting prsGo ahead, send a pull request that resolves this issueenhancement: new plugin ruleNew rule request for eslint-pluginpackage: eslint-pluginIssues related to @typescript-eslint/eslint-plugin

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions