typescript-best-practices

Enforce TypeScript best practices with Zod runtime validation and exhaustive handling.

Updated Mar 5, 2026
One-click install
npx skills add https://github.com/Himanshu040604/codex-skills-setup --skill typescript-best-practices-himanshu040604
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: typescript-best-practices
Source: https://github.com/Himanshu040604/codex-skills-setup/tree/main/assets/codex/skills/claude-import/skills/user/typescript-best-practices
Command: npx skills add https://github.com/Himanshu040604/codex-skills-setup --skill typescript-best-practices-himanshu040604

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill helps developers write more robust, maintainable, and error-free TypeScript code by enforcing best practices for type safety and state management.

Core Features & Use Cases

  • Type-First Development: Emphasizes defining types and interfaces before implementation.
  • Illegal State Prevention: Utilizes discriminated unions and branded types to make invalid states unrepresentable.
  • Exhaustive Handling: Ensures all code paths are considered, often with never checks in switch statements.
  • Runtime Validation: Integrates Zod for schema definition and data validation at application boundaries.
  • Use Case: When refactoring a complex JavaScript codebase to TypeScript, use this Skill to guide the process of defining types, ensuring all possible states are handled, and validating external data inputs.

Quick Start

Apply the typescript-best-practices skill to refactor the provided JavaScript code into a type-safe TypeScript structure.

Frequently Asked Questions about typescript-best-practices

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

FAQPage Schema
How do I make illegal states unrepresentable in TypeScript?

To make illegal states unrepresentable in TypeScript, you should use discriminated unions and branded types. This approach structurally prevents invalid state combinations, ensuring type safety and reducing runtime errors throughout your project.

What is the best way to validate external data inputs in TypeScript?

The best way to validate external data inputs in TypeScript is by integrating Zod for schema validation and data normalization. Zod enforces runtime validation at application boundaries, ensuring external data matches your defined types.

How do I ensure exhaustive handling in TypeScript switch statements?

To ensure exhaustive handling in TypeScript switch statements, implement `never` checks within your logic. This technique enforces all code paths are considered, generating compile-time errors if any cases are missed.

Can I use TypeScript best practices to refactor a JavaScript codebase?

Yes, you can refactor a JavaScript codebase using TypeScript best practices by enabling strict mode and applying type-first development. This process guides defining types, ensuring all possible states are handled, and validating external data inputs.

Do I need to enable strict mode for type-first development in TypeScript?

Yes, you need to enable strict mode for type-first development in TypeScript. Strict mode is required to enforce type safety, support const assertions, and fully leverage advanced features like discriminated unions.

When should I not use Zod for runtime validation in a TypeScript project?

You should not use Zod for runtime validation when handling internal, already type-safe data transfers within your TypeScript project. Zod is specifically designed for schema definition and data validation at application boundaries.