ts-best-practices

Enforce type-safe patterns in TypeScript projects with discriminated unions and type guards.

218|11|Updated Feb 22, 2026
One-click install
npx skills add https://github.com/poteto/noodle --skill ts-best-practices
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: ts-best-practices
Source: https://github.com/poteto/noodle/tree/main/.agents/skills/ts-best-practices
Command: npx skills add https://github.com/poteto/noodle --skill ts-best-practices

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

TypeScript type safety guidelines help teams write more reliable code by enforcing explicit type handling, safer casts, and stronger contracts across modules.

Core Features & Use Cases

  • Enforces discriminated unions, precise type narrowing, and robust type guards to prevent runtime type errors.
  • Guides safer handling of external data, API responses, and boundary validation to reduce nulls and unknowns.
  • Use Case: When evolving a public API or complex domain model, apply the patterns to keep types expressive and maintainable.

Quick Start

Audit a TypeScript file for unsafe casts and add proper guards and discriminated unions for stronger type safety.

Frequently Asked Questions about ts-best-practices

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

FAQPage Schema
How do I enforce type safety in TypeScript and prevent unsafe casts?

Type narrowing in TypeScript works by using discriminated unions and type guards to refine types within conditional blocks. This mechanism prevents runtime type errors by ensuring operations only execute on verified types.

What is the best way to handle API boundary validation in TypeScript?

The best way to handle API boundaries in TypeScript is to prefer unknown over any and use schema validation or type guards. This ensures safer handling of external data and reduces nulls and unknowns.

How do I perform exhaustiveness checks in TypeScript domain models?

Perform exhaustiveness checks in TypeScript by applying discriminated unions to complex domain models. This pattern enforces explicit type handling and ensures all possible cases are evaluated during code review scenarios.

Why should I use unknown over any in TypeScript code reviews?

Use unknown over any in TypeScript code reviews to enforce explicit type handling and safer casts. Unknown requires type narrowing or validation before use, strengthening contracts across modules and preventing runtime errors.

How do I audit a TypeScript file for unsafe casts and type errors?

Audit a TypeScript file for unsafe casts by checking for any type usage and explicit type assertions. Add proper type guards and discriminated unions to enforce type narrowing and achieve stronger type safety.