Skip to content

redundantTypeConstituents

Reports union and intersection type constituents that are redundant or override other types.

✅ This rule is included in the ts logical presets.

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:

  • any and unknown override all other union members
  • never is dropped from unions (except in return type position)
  • Primitive types like string override their literal types like "hello"

Within & intersections:

  • any and never override all other intersection members
  • unknown is dropped from intersections
  • Literal types like "hello" override their primitive types like string
type A = number | any;
type B = string | "literal";
type C = number & never;
type D = unknown & string;

This rule is not configurable.

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.

Made with ❤️‍🔥 in Boston by Josh Goldberg and contributors.