型安全性とエラーハンドリングルールを適用。any禁止、型ガード必須。TypeScript実装、型定義レビュー時に使用。
npx skills add https://github.com/shinpr/ai-coding-project-boilerplate --skill typescript-rules
プロジェクト規約を適用する前に、tsconfig、ランタイム・フレームワーク設定、lint・format設定、パスエイリアス、package scripts、代表的なモジュールを確認する。設定または確立済みのパターンに裏付けられたルールだけをプロジェクト固有として扱う。限られたパターンから導いた結論には推測であることを明記する。競合する規約によって公開契約、ランタイムの振る舞い、エラー境界が変わる場合は作業を止め、必要な情報源またはユーザー判断を具体的に示す。
データフローでの型安全性
入力層(unknown) → 型ガード → ビジネス層(型保証) → 出力層(シリアライズ)
Backend固有の型シナリオ:
unknownで受け、型ガードで検証unknown、バリデーション後に型確定unknownとして受け取り、根拠のある型アサーションが必要な場合は、その境界を所有するアダプター内に限定するPartial<T>を使用し、Vitestが設定されている場合にのみ型付きのvi.fn<[Args], Return>()を使用するクラス使用の判断基準
// 関数とinterface
interface UserService { create(data: UserData): User }
const userService: UserService = { create: (data) => {...} }
関数設計
// オブジェクト引数
function createUser({ name, email, role }: CreateUserParams) {}
依存性注入
// 依存性を引数で受け取る
function createService(repository: Repository) { return {...} }
非同期処理
async/awaitを使用するtry-catchを追加する。それ以外は、所有する境界までPromiseのrejectionを伝播させるPromise<Result>)フォーマット規則
PascalCase、変数・関数はcamelCasetsconfigまたは設定済みのビルドツールで宣言されたaliasを通じて使用する。それ以外は相対importを使用するクリーンコード原則
console.log()は削除エラー結果のルール: すべての失敗に対して、型付きの想定内エラーを返す、明記された要件に従って復旧する、診断情報を付加して伝播する、のいずれか1つを所有する結果として定める。同じ失敗を重複して記録しないよう、可観測性を所有する境界でログを出力する。
Fail-Fast原則: エラー時は速やかに失敗させ、不正な状態での処理継続を防ぐ
// 無効: 呼び出し元が必要とする失敗をフォールバックで隠している
catch (error) {
return defaultValue // エラーを隠蔽
}
// 情報を付加して明示的に伝播する
catch (error) {
throw new Error('処理失敗', { cause: error })
}
Result型パターン: エラーを型で表現し、明示的に処理
type Result<T, E> = { ok: true; value: T } | { ok: false; error: E }
// 使用例:エラーの可能性を型で表現
function parseUser(data: unknown): Result<User, ValidationError> {
if (!isValid(data)) return { ok: false, error: new ValidationError() }
return { ok: true, value: data as User }
}
カスタムエラークラス
export class AppError extends Error {
constructor(message: string, public readonly code: string, public readonly statusCode = 500) {
super(message)
this.name = this.constructor.name
}
}
// 用途別: ValidationError(400), BusinessRuleError(400), DatabaseError(500), ExternalServiceError(502)
層別エラー処理
構造化ログと機密情報保護
現在の信頼境界で許可されたフィールドだけをログに含める。認証情報、トークン、シークレット、決済情報、個人データはログ出力前に除去する。
非同期エラーハンドリング
unhandledRejectionやuncaughtExceptionを公開する場合は、アプリケーションのentry pointでランタイムレベルのhandlerを設定する。ライブラリではプロセスレベルの方針をhostに委ねるGuide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when building MCP servers to integrate external APIs or services, whether in Python (FastMCP) or Node/TypeScript (MCP SDK).
Automatically creates user-facing changelogs from git commits by analyzing commit history, categorizing changes, and transforming technical commits into clear, customer-friendly release notes. Turns hours of manual changelog writing into minutes of automated generation.
Use when implementation is complete, all tests pass, and you need to decide how to integrate the work - guides completion of development work by presenting structured options for merge, PR, or cleanup
Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when building MCP servers to integrate external APIs or services, whether in Python (FastMCP) or Node/TypeScript (MCP SDK).
React Native and Expo best practices for building performant mobile apps. Use when building React Native components, optimizing list performance, implementing animations, or working with native modules. Triggers on tasks involving React Native, Expo, mobile performance, or native platform APIs.
React and Next.js performance optimization guidelines from Vercel Engineering. This skill should be used when writing, reviewing, or refactoring React/Next.js code to ensure optimal performance patterns. Triggers on tasks involving React components, Next.js pages, data fetching, bundle optimization, or performance improvements.
Next.js best practices - file conventions, RSC boundaries, data patterns, async APIs, metadata, error handling, route handlers, image/font optimization, bundling
Use when starting feature work that needs isolation from current workspace or before executing implementation plans - creates isolated git worktrees with smart directory selection and safety verification
Take shinpr/ai-coding-project-boilerplate-skills-ja-typescript-rules from the repository into ~/.claude/skills for personal
use, or into .claude/skills inside a project.
The agent identifies a skill by the name field in its header. Two skills with the
same name cannot sit side by side — one of them will be ignored.