Description
Before You File a Proposal Please Confirm You Have Done The Following...
- I have searched for related issues and found none that match my proposal.
- I have searched the current rule list and found no rules that match my proposal.
- I have read the FAQ and my problem is not listed.
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.