TS-TYPE0001 · non_erasable_construct
Count the constructs that stop TypeScript from being erased rather than compiled.
This is a deterministic rule for typescript. Read its implementation.
Definition
Section titled “Definition”Count the declarations whose meaning survives type stripping, which are an enum, a const enum, a runtime namespace, a constructor parameter property, and import =. Each generates
JavaScript rather than disappearing with the types, which is why a runtime that strips types
cannot run them and why TypeScript 5.8 added erasableSyntaxOnly to find them. Those semantics
require emitted code.
The cost is not only the build step. An enum produces an object with a reverse mapping that
JSON never round-trips, a namespace produces a closure that tree shaking cannot open, and a
parameter property hides a field declaration inside a signature.
Evidence
Section titled “Evidence”Each finding names the construct, its kind, and the line it is written on, counted against the module’s own length. The repair is a choice, since rewriting the construct and deciding this project never strips types are both real answers. The value is the number found.
Exceptions
Section titled “Exceptions”A project that compiles through a bundler and never intends to strip types can keep them, and should say so by disabling this rule rather than by leaving it failing. A declaration file describing an external library states constructs it does not own.
Examples
Section titled “Examples”enum Status { Active = 'ACTIVE' }class Engine { constructor(private limit: number) {} }const Status = { Active: 'ACTIVE' } as const;type Status = (typeof Status)[keyof typeof Status];References
Section titled “References”- Cites “TypeScript documentation”, 5.8 release notes, the
erasableSyntaxOnlyoption. Open reference - Cites “Node.js documentation”, type stripping. Open reference
- Cites “TypeScript documentation”, handbook, enums and their runtime output. Open reference