enforce-erasable-syntax-only
Installation
SKILL.md
Summary
Limit TypeScript usage to syntax that disappears completely during compilation (Type Erasure). Do NOT use enum, namespace, or parameter properties (in constructors) as they emit JavaScript code at runtime.
Rationale
- Single Source of Truth: TypeScript should only label types, not generate logic. This ensures compatibility with tools like Babel, SWC, or esbuild which often strip types based on syntax.
- Bundle Size: Features like
enumgenerate complex IIFE code in JavaScript. - Predictability: It is clearer when the JS output is structurally identical to the TS source (minus types).
Guidance
- Enums: Replace with
constobjects (as Const enum) or String Unions (type State = 'active' | 'inactive'). - Namespaces: Use ES Modules (
import/export) instead. - Constructors: Declare properties explicitly in the class body, not in the constructor arguments.