redundantTypeConstituents
Reports union and intersection type constituents that are redundant or override other types.
✅ This rule is included in the tslogicalandlogicalStrictpresets.
Some types can override other types in a union or intersection, making certain constituents redundant. TypeScript’s set theory of types includes cases where a constituent type might be useless in the parent union or intersection.
Within | unions:
anyandunknownoverride all other union membersneveris dropped from unions (except in return type position)- Primitive types like
stringoverride their literal types like"hello"
Within & intersections:
anyandneveroverride all other intersection membersunknownis dropped from intersections- Literal types like
"hello"override their primitive types likestring
Examples
Section titled “Examples”44AE44AE44AE44AEOptions
Section titled “Options”This rule is not configurable.
When Not To Use It
Section titled “When Not To Use It”Some projects choose to occasionally include a redundant type constituent for documentation purposes.
For example, some unions intentionally include a redundant string in unions containing unknown to indicate intent.
You might consider using Flint disable comments and/or configuration file disables for those specific situations instead of completely disabling this rule.
Further Reading
Section titled “Further Reading”- TypeScript Handbook: Union Types
- TypeScript Handbook: Intersection Types
- Wikipedia: Bottom Type
- Wikipedia: Top Type
