types-and-interfaces

Derive TypeScript types from Zod schemas for runtime validation consistency.

5|Updated Apr 1, 2026
One-click install
npx skills add https://github.com/TechyMT/claude-code-superpowers --skill types-and-interfaces
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: types-and-interfaces
Source: https://github.com/TechyMT/claude-code-superpowers/tree/main/skills/types-and-interfaces
Command: npx skills add https://github.com/TechyMT/claude-code-superpowers --skill types-and-interfaces

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Many TypeScript projects split type declarations and runtime validators, causing drift between compile-time types and runtime behavior that leads to crashes and unhandled cases. This Skill codifies a discipline to derive runtime validation and TypeScript types from the same Zod schema, use discriminated unions for multi-variant outputs, and enforce DeepImmutable AppState to prevent accidental mutation.

Core Features & Use Cases

  • Schema-as-source-of-truth: define inputSchema with Zod and derive TypeScript types with z.infer to avoid duplicate, diverging definitions.
  • Discriminated union outputs: use z.discriminatedUnion for tool outputs so TypeScript exhaustiveness and narrowing eliminate missing-case bugs.
  • Immutable AppState: wrap AppState in DeepImmutable to force immutable updates via setAppState and make state transitions explicit.
  • Use Case: migrating a codebase where manual validators and interfaces disagree, or adding a new tool that must validate LLM JSON output and provide multiple result shapes.

Quick Start

Convert this tool's manual validation and interfaces into a Zod inputSchema, derive the TypeScript type with z.infer, add an outputSchema as a discriminated union if the tool can return multiple result kinds, and make AppState DeepImmutable.

Frequently Asked Questions about types-and-interfaces

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

FAQPage Schema
How do I keep TypeScript types and runtime validation in sync?

To keep TypeScript types and runtime validation in sync, define a Zod schema as the source of truth and derive the TypeScript type using z.infer, eliminating duplicate and diverging definitions.

How do I enforce immutable state updates in TypeScript?

To enforce immutable state updates in TypeScript, wrap your AppState in a DeepImmutable type to force explicit state transitions via setAppState and prevent accidental mutations.

How do I validate multiple result shapes from LLM JSON output?

To validate multiple result shapes from LLM JSON output, use a Zod discriminatedUnion for your output schema, enabling TypeScript exhaustive narrowing to eliminate missing-case bugs.

Why does my manual validator disagree with my TypeScript interface?

Manual validators and TypeScript interfaces disagree because maintaining duplicate definitions causes drift between compile-time types and runtime behavior, leading to unhandled cases and crashes.

Does Zod strict-object validation prevent unknown keys?

Zod strict-object validation does prevent unknown keys by rejecting unrecognized properties during JSON validation, which stops unexpected payload data from causing runtime crashes.