スキル一覧に戻る
ffMathy

typescript-type-safety

by ffMathy

My digital assistant that runs the house.

2🍴 0📅 2026年1月24日
GitHubで見るManusで実行

SKILL.md


name: typescript-type-safety description: TypeScript type safety guidelines. Use this when writing TypeScript code, especially when handling errors or unknown data types.

TypeScript Type Safety

CRITICAL: Never use any type - it defeats TypeScript's purpose.

Rules

  1. Use proper types for all data structures
  2. Use unknown for truly unknown data, then narrow with type guards
  3. Use type assertions sparingly and only when verified
  4. Enable strict mode in tsconfig.json

Error Handling

BAD - Using any:

server.on('error', (error: any) => {
  console.error('Server error:', error.message);
  if (error.details) {
    console.error('Details:', error.details.message);
  }
});

GOOD - Proper Type Assertion:

server.on('error', (error) => {
  const typedError = error as Error & {
    details?: { message?: string };
  };
  console.error('Server error:', typedError.message);
  if (typedError.details?.message) {
    console.error('Details:', typedError.details.message);
  }
});

EVEN BETTER - Type Guard:

function isErrorWithDetails(error: unknown): error is Error & { details: { message: string } } {
  return error instanceof Error &&
    typeof (error as any).details === 'object' &&
    typeof (error as any).details.message === 'string';
}

server.on('error', (error) => {
  console.error('Server error:', error instanceof Error ? error.message : String(error));
  if (isErrorWithDetails(error)) {
    console.error('Details:', error.details.message);
  }
});

Why any is Problematic

  • Disables all TypeScript checking
  • No autocomplete in IDE
  • Typos caught only at runtime
  • Makes refactoring dangerous
  • Defeats the purpose of TypeScript

When to Use Type Assertions

  • Only after verifying the shape/type at runtime
  • When TypeScript can't infer but you know the type
  • Use as assertions, not angle brackets
  • Document why the assertion is safe

スコア

総合スコア

60/100

リポジトリの品質指標に基づく評価

SKILL.md

SKILL.mdファイルが含まれている

+20
LICENSE

ライセンスが設定されている

+10
説明文

100文字以上の説明がある

0/10
人気

GitHub Stars 100以上

0/15
最近の活動

3ヶ月以内に更新がある

0/10
フォーク

10回以上フォークされている

0/5
Issue管理

オープンIssueが50未満

+5
言語

プログラミング言語が設定されている

+5
タグ

1つ以上のタグが設定されている

0/5

レビュー

💬

レビュー機能は近日公開予定です