mcpField
R
runtime-type-reconstruction

runtime-type-reconstruction

github.com/marius-townhouseDevelopment644 installsUpdated 38w ago
Repository

About runtime-type-reconstruction

A TypeScript skill for validating runtime data against types using schema libraries such as io-ts, zod, or runtypes. It is intended for developers who need runtime checks and static types from a shared schema.

Key features

  1. 01Validate data at runtime
  2. 02Parse JSON with type safety
  3. 03Define schemas with io-ts, zod, or runtypes
  4. 04Derive static types from schemas

Use cases

  1. 01Check external data against expected shapes
  2. 02Parse JSON safely
  3. 03Build validation schemas
  4. 04Keep runtime validation aligned with TypeScript types

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/marius-townhouse/effective-typescript-skills --skill runtime-type-reconstruction

After installing, type/runtime-type-reconstructionin Claude Code to confirm it loaded.

Details

From the project README

Know How to Reconstruct Types at Runtime

Overview

TypeScript types are erased at runtime, but sometimes you need to validate that runtime data matches your types. Use libraries like io-ts, zod, or runtypes to define schemas that provide both runtime validation and static types. This ensures your types match reality.

When to Use This Skill

  • Validating data at runtime
  • Parsing JSON with type safety
  • Types need runtime checks
  • Using io-ts, zod, or runtypes
  • Building validation schemas

The Iron Rule

Use validation libraries like zod or io-ts to get both runtime validation and TypeScript types from a single source of truth.

Example with Zod

import { z } from 'zod';

// Define schema once
const UserSchema = z.object({
  id: z.string(),
  name: z.string(),
  email: z.string().email(),
  age: z.number().optional(),
});

// Get TypeScript type from schema
type User = z.infer<typeof UserSchema>;

// Runtime validation
const result = UserSchema.safeParse(unknownData);
if (result.success) {
  // result.data is typed as User
  console.log(result.data.name);
} else {
  console.error(result.error);
}

Reference

  • Effective TypeScript, 2nd Edition by Dan Vanderkam
  • Item 74: Know How to Reconstruct Types at Runtime

Comments

Markdown supported