typescript-best-practices

Enforce type-safe patterns in TypeScript and JavaScript code reviews.

Updated Aug 23, 2026
One-click install
npx skills add https://github.com/awfixers-stuff/opencode-config --skill typescript-best-practices-awfixers-stuff
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: typescript-best-practices
Source: https://github.com/awfixers-stuff/opencode-config/tree/main/skills/typescript-best-practices
Command: npx skills add https://github.com/awfixers-stuff/opencode-config --skill typescript-best-practices-awfixers-stuff

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Prevents runtime errors and invalid program states by promoting type-first design, clear domain modelling, and disciplined runtime validation practices for TypeScript and JavaScript codebases.

Core Features & Use Cases

  • Make illegal states unrepresentable: use discriminated unions, branded types, and const assertions to ensure only valid combinations are possible at compile time.
  • Exhaustive handling and safer patterns: advocate for exhaustive switch checks, never-based guards, and simplified complex types for clearer reasoning and maintainability.
  • Runtime validation with Zod: define schemas as the single source of truth, infer TypeScript types from schemas, and choose safeParse versus parse appropriately for input validation and trust boundaries.
  • Use Case: validate and normalize API responses and user-submitted forms, convert them into strongly typed domain models, and reduce production crashes from malformed data.

Quick Start

Ask the assistant to review a TypeScript file and apply typescript-best-practices by introducing discriminated unions, branded types where appropriate, and Zod schemas for any external input.

Frequently Asked Questions about typescript-best-practices

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

FAQPage Schema
How do I prevent runtime errors in TypeScript when handling API responses?

Prevent runtime errors in TypeScript by applying Zod schemas at trust boundaries to parse and validate API responses, converting external data into strongly typed domain models using safeParse for untrusted input.

What's the best way to make illegal states unrepresentable in TypeScript?

Make illegal states unrepresentable by using discriminated unions, branded types, and const assertions to ensure only valid state combinations are possible at compile time.

When should I use safeParse versus parse with Zod runtime validation?

Use Zod safeParse for external input validation at trust boundaries where data may be malformed, and use parse for internal data already guaranteed safe by TypeScript type definitions.

How do I enforce exhaustive switch checks in TypeScript?

Enforce exhaustive switch checks in TypeScript by using never-based guards and discriminated unions, ensuring all possible cases are handled and simplifying complex types for maintainability.

Can I apply TypeScript best practices to JavaScript and tsconfig.json files?

Yes, these type-safe patterns apply to .ts, .tsx, .js files and tsconfig.json, guiding library development, API handlers, and React component code reviews for safer JavaScript and TypeScript codebases.

Why should I infer TypeScript types from Zod schemas?

Infer TypeScript types from Zod schemas to establish a single source of truth, eliminating duplicate type definitions and ensuring runtime validation automatically stays synchronized with compile-time types.