reviewing-type-safety

Enforce TypeScript type-safety patterns with strictNullChecks and type guards.

11|1|Updated Aug 6, 2025
One-click install
npx skills add https://github.com/thkt/claude-config --skill reviewing-type-safety
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: reviewing-type-safety
Source: https://github.com/thkt/claude-config/tree/main/skills/reviewing-type-safety
Command: npx skills add https://github.com/thkt/claude-config --skill reviewing-type-safety

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

TypeScript type safety patterns and best practices to improve coverage and reduce runtime errors.

Core Features & Use Cases

  • Type guards and discriminated unions
  • Safe use of any vs unknown
  • Strict mode recommendations and enforcement

Quick Start

Annotate functions and data structures with explicit types to enable strong compile-time checks.

Frequently Asked Questions about reviewing-type-safety

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

FAQPage Schema
How do I enforce type safety in TypeScript to catch errors at compile time?

Type safety in TypeScript uses explicit type annotations, strict mode configuration, and type guards to prevent runtime errors. Enable strictNullChecks and Strict mode in tsconfig.json, annotate function parameters and return types, and use discriminated unions and type guards to narrow unsafe types like any and unknown.

What's the difference between any and unknown in TypeScript?

unknown is a safe alternative to any that requires type narrowing before use, preventing accidental unsafe operations. any bypasses all type checking. Use unknown for untyped data sources and type guards to validate the actual type before accessing properties or methods.

How do I use discriminated unions to improve type safety?

Discriminated unions combine a literal type field with union types to enable exhaustive pattern matching. Define a common property that distinguishes each union member, then use type guards or switch statements to narrow the type safely and eliminate unsafe type assertions.

Can I achieve 95% type coverage in an existing TypeScript codebase?

Yes. Incrementally add explicit type annotations, enable strictNullChecks, eliminate implicit any instances, replace unsafe any usage with unknown or specific types, and use type guards. This workflow applies to front-end and back-end projects and can be integrated into CI checks to enforce compliance.

What does strict mode in TypeScript enforce?

Strict mode enables strictNullChecks, strictFunctionTypes, strictBindCallApply, strictPropertyInitialization, noImplicitAny, and other checks. It prevents null/undefined from being assigned to any type, catches implicit any declarations, and validates function signatures to eliminate entire categories of type errors.

When should I use type assertions instead of type guards?

Minimize type assertions; use type guards instead to safely narrow types. Type assertions bypass checks and hide errors. Reserve assertions only for cases where you have external knowledge the compiler lacks, and document why. Prefer type guards, discriminated unions, and unknown for safe type narrowing.