deslop/duplicate-type-definition

Flag named type aliases/interfaces with the same structural shape duplicated across files; extract one shared type.

  • Category: Architecture
  • Severity: warn
  • Source: deslop-js
  • Framework: global
  • Enabled when: react-doctor deadCode analysis enabled (default true); whole-project scan only — skipped in --diff/--staged modes
  • Documentation: https://github.com/millionco/deslop-js

Validation prompt

Use this to decide whether a fired diagnostic is real or a false positive.

Fires from detectDuplicateTypeDefinitions when two or more named declarations (TSTypeAliasDeclaration or TSInterfaceDeclaration, .d.ts/declaration files skipped) hash to the same structuralHash across at least two distinct files: the high-confidence reason reads 'N identically-named type definitions of the same shape across M files — extract a shared definition', and the medium-confidence variant reads 'N structurally-identical type definitions detected across M files under different names (NameA, NameB, ...) — confirm whether the rename is intentional', where the parenthesized list is the join of every distinct name in the cluster (so a three-name cluster renders three names, not two). Suppress when the matching types are coincidentally identical but model genuinely independent concepts (e.g. a Point in a geometry module and a Coordinate in a maps module, or two DTOs mirroring separate external APIs) — merging them into one shared definition forges a contract that would force unrelated code to change together and break the moment one side legitimately diverges; the different-names/medium variant explicitly asks you to confirm the rename is intentional and is the common false positive.

Fix prompt

Use this once validation confirms the diagnostic is real.

When the duplicates are truly the same concept, delete all but one declaration, export it from a shared module (e.g. export type User = { id: string; name: string } in types.ts), and replace the others with import type { User }; for the different-names case, pick the clearer name and re-point every reference to it. Only do this when the types must stay in lockstep — if they describe separate concerns, leave them duplicated rather than coupling unrelated code to one shape. See https://github.com/millionco/deslop-js