TS-TYPE0002 · escape_hatch_density
Measure how much of a module steps around what its type system proved.
This is a deterministic rule for typescript. Read its implementation.
Definition
Section titled “Definition”Return the share of lines carrying a type assertion, a non-null assertion, an any, or a
suppression comment. Each one is a promise to the compiler with nothing behind it, and the
compiler stops checking exactly where the promise was made. One is a considered decision. A
module where a tenth of the lines make one has stopped being typed, and no per-occurrence rule
says so, because each occurrence looked reasonable on its own.
Evidence
Section titled “Evidence”Each finding names one hatch, its kind, and the line it sits on, beside the module’s own length and the share every hatch together comes to. The repair is a choice, since validating at the boundary and excluding a declaration file are different answers to the same reading. The value is that share.
Exceptions
Section titled “Exceptions”A boundary that receives untyped data legitimately asserts once it has validated, and a schema validator is the usual way to make that assertion earn its keep. A declaration file describing an untyped library is assertions by nature. Both belong in a project’s exclusions rather than in a raised ceiling.
Examples
Section titled “Examples”A 200-line module with two assertions returns 1.0. The same module with forty returns 20.0
and is no longer type checked in any meaningful sense.
References
Section titled “References”- Generalizes typescript-eslint no-explicit-any
- Generalizes typescript-eslint no-non-null-assertion. Open reference
- Cites “TypeScript documentation”, handbook, type assertions and their limits. Open reference
- Cites “Zod documentation”, validating what the type system cannot prove at runtime. Open reference