Claude Code TypeScript Skill for Discriminated Result Unions
Model successful and failed results as separate branches under strict type checking. Narrow at the call site and check both outcomes.
中文Install in Claude Code
Use Claude Code with the pinned skill and a strict TypeScript project. Verify using the project's type checker and tests.
- Get the complete `skills/typescript` directory from the pinned revision.
- Copy it into the target project's `.claude/skills/` and confirm `.claude/skills/typescript/SKILL.md`. Start Claude Code at the project root and describe a task matching the skill's purpose.
Example task
Model a fictional CSV reading-list import. Success returns an imported row count. Failure returns a readable reason. Exercise one titled record and one blank title.What to check
The success branch safely exposes the count and failure exposes the reason. Cover both cases and check that fields from the other branch are rejected.
Original SKILL.md on GitHub · Updated
Frequently asked question
Why not put every field in one object as optional?
A discriminated union expresses which fields can coexist. Narrowing on the tag gives callers the appropriate type.