What problem does it solve?
This skill addresses the maintenance burden of discriminated unions in TypeScript by replacing fragile switch-case logic with a formal visitor pattern, ensuring that adding new variants triggers compile-time errors in all consumer locations.
Core Features & Use Cases
- Type-Safe Dispatch: Enforces exhaustive handling of union variants across multiple dispatch sites like renderers or serializers.
- Frozen Invariants: Provides a standardized structure for immutable nodes that prevents accidental mutation and ensures prototype integrity.
- Use Case: When refactoring a complex AST with multiple node types, this pattern ensures that every time a new node type is added, the compiler forces you to update all visitors, preventing silent runtime failures.
Quick Start
Apply the ast-visitor-pattern structure to the current discriminated union by defining an abstract base class with an accept method and a corresponding visitor interface.