code-gen-independent

Clarify that TypeScript types are erased at runtime for code generation.

Updated Jul 17, 2017
One-click install
npx skills add https://github.com/luyi985/lyi-bash --skill code-gen-independent
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: code-gen-independent
Source: https://github.com/luyi985/lyi-bash/tree/main/ai/skills/code-gen-independent
Command: npx skills add https://github.com/luyi985/lyi-bash --skill code-gen-independent

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill clarifies that TypeScript types are erased at runtime and that code generation proceeds independently of static type errors, helping developers avoid runtime surprises.

Core Features & Use Cases

  • Educational clarity: explains the distinction between compile-time types and runtime values.
  • Practical guidance: provides patterns like runtime checks and classes to model runtime behavior, and contrasts with type-level constructs.
  • Use case: when you need to reason about code generation from TypeScript sources without relying on types at runtime.

Quick Start

Provide a small TypeScript example that demonstrates that types are erased at runtime.

Frequently Asked Questions about code-gen-independent

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
Why does TypeScript code generation ignore static type errors at runtime?

TypeScript code generation ignores type errors because static types are erased at runtime, meaning generated runtime behavior depends solely on runtime values and constructs, not compile-time type definitions.

How do I handle runtime branching in TypeScript when types are erased?

To handle runtime branching when types are erased, use runtime constructs like classes and discriminated unions instead of compile-time types to model and verify runtime behavior accurately.

What is the difference between compile-time types and runtime values in TypeScript?

Compile-time types in TypeScript exist only for static checking and are fully erased during code generation, whereas runtime values are the actual JavaScript constructs that execute and drive runtime behavior.

Can I rely on TypeScript interfaces to check types during code generation?

No, you cannot rely on TypeScript interfaces during code generation because static types are erased at runtime; you must use runtime constructs like classes or discriminated unions for type checks.

Does TypeScript type erasure affect JavaScript runtime behavior?

TypeScript type erasure does not affect JavaScript runtime behavior because types are removed during compilation, ensuring that generated JavaScript runs identically regardless of static type errors present in the source.

When do I need to separate compile-time types from runtime values in TypeScript?

You need to separate compile-time types from runtime values when generating runtime behavior from TypeScript sources, ensuring you avoid type-based runtime branching and rely on runtime constructs instead.