typescript-rules

Enforce TypeScript type safety with type guards and explicit error handling.

225|24|Updated Jul 27, 2025
One-click install
npx skills add https://github.com/shinpr/ai-coding-project-boilerplate --skill typescript-rules
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: typescript-rules
Source: https://github.com/shinpr/ai-coding-project-boilerplate/tree/main/.claude/skills-ja/typescript-rules
Command: npx skills add https://github.com/shinpr/ai-coding-project-boilerplate --skill typescript-rules

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill eliminates the guesswork in documentation creation by providing clear criteria for when to create PRD, ADR, Design Doc, and Work Plan requirements.

Core Features & Use Cases

  • Backend Type Safety: Ensure data flow type safety from input (unknown) to business layer (type guaranteed) with proper error handling patterns and dependency injection practices.

Core Features & Use Cases

  • Type Guard Implementation: Use unknown type with proper validation functions for external API responses and database operations.

Quick Start

Use this Skill to implement a new API endpoint with proper type definitions, async/await error handling, and performance optimization techniques.

Quick Start

Apply TypeScript rules to create a service function with proper Result type pattern and custom error classes for domain-specific error handling.

Quick Start

Create a user service with dependency injection and proper error propagation to upper layers.

Frequently Asked Questions about typescript-rules

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

FAQPage Schema
How do I enforce type safety in TypeScript backend code?

Type safety in TypeScript backend code is enforced by applying type guards to validate unknown inputs from APIs and databases, then propagating guaranteed types through business logic layers. Use the unknown type at entry points, implement validation functions, and maintain explicit types throughout the data flow to eliminate runtime errors.

What's the best way to handle errors in TypeScript API endpoints?

Handle errors in TypeScript API endpoints using custom error classes for domain-specific exceptions, async/await patterns with explicit error propagation, and layer-specific error handling. Implement a Result type pattern to encode success and failure states, allowing upper layers to handle errors appropriately.

How do I validate external API responses in TypeScript?

Validate external API responses by treating them as unknown type, implementing type guard functions to check structure and values, then converting validated data to your internal types. This ensures type safety when integrating with third-party APIs and legacy systems.

Can I use dependency injection with TypeScript type safety?

Yes, dependency injection works with TypeScript type safety through parameterization—pass dependencies as function parameters with explicit types rather than relying on globals or service locators. This maintains type guarantees and makes error handling and testing more straightforward.

Do I need custom error classes for backend services?

Custom error classes enable structured, domain-specific error handling in backend services. They allow layer-specific error processing—catching and transforming errors appropriately as they propagate—and provide type-safe error context for logging and API responses.

How do I structure form input validation in TypeScript?

Structure form input validation by treating raw input as unknown, applying type guard functions to validate structure and constraints, then converting to typed domain objects. This pattern applies to API request bodies, form submissions, and any untrusted external data.