Skip to main content

TypeScript analyzer

TypeScript Generics Usage

Flags generic-type arity, unused type parameters, broad constraints, and missing constraints.

technical-debt ts-generics

TypeScript Generics Usage

Flags generic-type arity, unused type parameters, broad constraints, and missing constraints.

Generic type parameters are TypeScript's main tool for safe abstraction, but they have costs: each parameter is a degree of freedom callers must understand and satisfy. High arity (5+ type parameters), unused parameters, single-use parameters, and overly broad constraints all signal that a generic is overspecified for its actual use sites.

Severity guide

info
Generic usage is unusual but acceptable; review during a refactor.
warning
Generic shape will confuse callers or hide bugs; refactor recommended.
critical
Not currently emitted by this analysis.

Remediation

Reduce type-parameter arity, remove unused parameters, narrow over-broad constraints, and add constraints where they would prevent invalid uses.

Reduce type-parameter arity, remove unused parameters, narrow over-broad constraints, and add constraints where they would prevent invalid uses.

Documentation