Skip to content

Enhancement: [no-redundant-type-constituents] Use assignability checking for redundancy checks #7742

Open
@JoshuaKGoldberg

Description

@JoshuaKGoldberg

Before You File a Proposal Please Confirm You Have Done The Following...

My proposal is suitable for this project

  • I believe my proposal would be useful to the broader TypeScript community (meaning it is not a niche proposal).

Link to the rule's documentation

https://typescript-eslint.io/rules/no-redundant-type-constituents

Description

Right now, no-redundant-type-constituents is very limited:

This rule plays it safe and only works with bottom types, top types, and comparing literal types to primitive types.

But sometimes an intersection or union type will have two constituents where one constituent is equivalent to a superset of the other. It'd be nice to report on those cases too. Or, heck, even cases where they're deeply equal, but declared as different object types.

Fail

type ShallowEqual = number | number;
type DeepEqual = { a: string } | { a: string };
type Superset = { a: string } | { a: "b" | "c" };

Pass

type ShallowEqual = string | number;
type DeepEqual = { a: string } | { a: number };
type Superset = { a: string } | { a: "b" | "c" | 0 };

Additional Info

If we could use a type assignability / relationship API (microsoft/TypeScript#9879), then we could catch those. Filing this long-standing rule feature request for tracking.

This feature request could also be said for no-duplicate-type-constituents. Debatably maybe it should. 🤷 I'm mostly filing this as fodder for microsoft/TypeScript#9879.

Metadata

Metadata

Assignees

No one assigned

    Labels

    accepting prsGo ahead, send a pull request that resolves this issueenhancement: plugin rule optionNew rule option for an existing eslint-plugin rulepackage: 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