TypeScript Structural Quality
Detects singleton patterns, undocumented empty catches, primitive throws and direct use of the global object; reports `using` declarations and counts what a single file can prove about factories and injection.
Beyond TypeScript-specific shape concerns, codebases accumulate structural anti-patterns: catch blocks that swallow errors without a word, singletons that hide coupling, primitive values thrown where an Error belongs, and repeated use of the global object that makes code hard to test. This analysis flags those. The score is 100 minus the deductions for singletons, empty catches and primitive throws, and every deduction has a finding that names it; use of the global object is reported as information and costs nothing, and good patterns are reported or counted and never added back to the score.
A single file cannot prove what another file declares, so the analysis does not guess. A catch block that contains a comment is documented intent, not an oversight. A parameter or variable that happens to be called window, a typeof window feature check, and declare global are not uses of the global. Whether an imported name is a concrete class, whether a createX() function hides an abstraction, and whether an injected type is an interface are questions about other files: they are answered by the project-scoped design-principle checks (ts-design-principles), and here they are counted only when the abstraction is declared in the same file.
Severity guide
- info
- A `using` declaration is in use, or the file reads the global object several times (expected in browser-facing modules).
- warning
- A structural anti-pattern is present and should be reviewed.
- critical
- Not currently emitted by this analysis.
Remediation
Handle or document every caught error; throw Error objects, not primitives; keep use of the global object in one environment-boundary module.
Give every catch block a body: log, rethrow or handle the error, or state in a comment inside the block why ignoring it is correct. Throw an Error (or a subclass per category) instead of a string or number. Keep window / globalThis access in one small environment-boundary module and pass what the rest of the code needs. Replace a private-constructor singleton with an injected instance.