TypeScript Declaration Shape
Flags interface/class/namespace shape problems: empty interfaces, oversized definitions, deep inheritance, declaration merging, and missing return types.
The way TypeScript declarations are shaped affects readability, refactor cost, and how well downstream tooling can leverage the type system. Empty interfaces hide intent, oversized behavioural interfaces resist focused changes, deep inheritance trees obscure data flow, and namespaces resist the module-aware tooling that ES modules unlock. This analysis surfaces these shape problems so they can be addressed before they entrench.
Each rule names only what it is true of. An interface is empty only when it declares nothing at all: one with a call, construct or index signature, one that extends another interface, and one that merges with a second declaration are not. A large shape is reported only when it declares behaviour (six or more methods or function-typed members) and is neither a component's props (…Props) nor a state container (…State), whether it is written as an interface or as an object type alias; a plain data record has no implementor to burden. A namespace is reported only when it emits code: declare namespace and a namespace inside declare global are erased. Inheritance depth is measured within the file only: a class extending a base declared in another module is measured at depth 1, so cross-module hierarchies read shallower than they are; resolving imported bases needs the type checker and belongs to the type-aware lane.
Severity guide
- info
- A declaration shape is unusual but not problematic, so review and refactor when convenient.
- warning
- A declaration shape is hindering readability or refactor cost; the listed item should be addressed.
- critical
- Not currently emitted by this analysis.
Remediation
Replace empty interfaces with type aliases, split oversized interfaces, prefer ES modules over namespaces, and add explicit return types to exported functions.
Replace empty interfaces with type aliases, split oversized interfaces, prefer ES modules over namespaces, and add explicit return types to exported functions.