type-safety

Review TypeScript code for runtime-boundary validation and type-narrowing improvements.

1|Updated May 6, 2026
One-click install
npx skills add https://github.com/jacob-balslev/skill-graph --skill type-safety-jacob-balslev
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: type-safety
Source: https://github.com/jacob-balslev/skill-graph/tree/main/marketplace/skills/type-safety
Command: npx skills add https://github.com/jacob-balslev/skill-graph --skill type-safety-jacob-balslev

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

It helps you prevent incorrect behavior that happens when developers assume compile-time types prove runtime correctness, instead of validating values at I/O boundaries.

Core Features & Use Cases

  • Soundness vs unsoundness: Understand what guarantees TypeScript (and gradual type systems) actually provide, and where they leak (escape hatches, assertions, any, and unchecked assumptions).
  • Safer refinement patterns: Use narrowing (including discriminated unions) to avoid casts and preserve correctness.
  • Exhaustiveness verification: Enforce complete handling of unions so missing cases fail at compile time.
  • Runtime boundary discipline: Validate external data (parsed JSON, env vars, storage, network responses) with runtime validators before trusting internal types.

Quick Start

Use the type-safety skill to review a TypeScript change and identify where external inputs are being treated as typed without boundary validation, then propose narrowing and exhaustiveness improvements.

Frequently Asked Questions about type-safety

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

FAQPage Schema
How do I prevent TypeScript type errors at runtime when parsing external JSON?

Prevent TypeScript runtime type errors by validating external JSON at I/O boundaries using runtime schemas before trusting internal types. Ensure compile-time soundness by replacing unchecked casts with narrowing and discriminated unions to avoid unsafe assumptions.

What is soundness in gradual type systems and where do type guarantees leak?

Soundness in gradual type systems means compile-time types guarantee correctness, but leaks occur through escape hatches like `any`, assertions, and unchecked assumptions. Enforce soundness by preferring `unknown` over `any` and applying runtime boundary validation.

What's the best way to handle missing cases in a TypeScript union type?

The best way to handle missing cases in a TypeScript union is exhaustiveness verification, which enforces complete handling of unions so missing cases fail at compile time. Combine this with narrowing and discriminated unions rather than unchecked casts.

Why does TypeScript assume my network response matches the interface without validation?

TypeScript assumes network responses match interfaces because it provides compile-time checks without runtime guarantees. Apply runtime boundary discipline by validating external data with runtime validators before trusting internal types, ensuring actual runtime correctness.

When should I use unknown instead of any in TypeScript for safer narrowing?

Use `unknown` instead of `any` in TypeScript when receiving untrusted external data to enforce safer narrowing. `unknown` requires explicit type checking before use, preserving compile-time soundness and preventing unsafe assumptions that lead to runtime defects.