Enforces type safety in TypeScript/Python implementations. Any/any types strictly prohibited. Use when processing API responses, integrating external libraries, or implementing data validation. Supports strict mode configuration and type guard implementation.
Enforces strict type safety in TypeScript/Python by prohibiting any/Any types. Triggers when implementing APIs, integrating libraries, or validating data to ensure explicit type definitions and type guards.
/plugin marketplace add sumik5/sumik-claude-plugin/plugin install sumik@sumikThis skill inherits all available tools. When active, it can use any tool Claude has access to.
ANTI-PATTERNS.mdPYTHON.mdREFERENCE.mdTYPESCRIPT.mdこのスキルは以下のファイルで構成されています:
❌ 絶対禁止:
- any型の使用
- Function型(anyと同等)
- non-null assertion(!)の濫用
✅ 代替手段:
- 明示的な型定義(interface/type)
- unknown + 型ガード
- ジェネリクス
- Utility Types
❌ 絶対禁止:
- Any型の使用
- bare except
- eval/exec
✅ 代替手段:
- 明示的な型ヒント
- TypedDict
- Protocol(構造的部分型)
- Union型
すべての関数、変数に型を明示的に定義します。
TypeScript:
function getUserById(id: string): User | null {
// 実装
}
Python:
def get_user_by_id(user_id: str) -> Optional[User]:
# 実装
pass
unknown型や不明な型は、型ガードで安全に処理します。
TypeScript:
function isUser(data: unknown): data is User {
return typeof data === 'object' &&
data !== null &&
'id' in data &&
'name' in data
}
if (isUser(data)) {
console.log(data.name) // 型安全
}
Python:
from typing import TypeGuard
def is_user(data: object) -> TypeGuard[User]:
return isinstance(data, dict) and \
'id' in data and 'name' in data
if is_user(data):
print(data['name']) # 型安全
TypeScript: strict mode有効化
{
"compilerOptions": {
"strict": true,
"noImplicitAny": true,
"strictNullChecks": true
}
}
Python: mypy/pyright実行
mypy src/
pyright src/
| 状況 | 悪い例 | 良い例 |
|---|---|---|
| API レスポンス | response: any | response: ApiResponse |
| 不明な型 | data: any | data: unknown + 型ガード |
| 複数の型 | value: any | value: string | number |
| オプショナル | user!.name | user?.name ?? 'Unknown' |
| 配列操作 | items: any[] | items: User[] |
src/
├── types/
│ ├── api.ts # API型定義
│ ├── models.ts # データモデル型
│ └── utils.ts # ユーティリティ型
├── guards/
│ └── type-guards.ts # 型ガード関数
└── ...
コードの型安全性は以下のレベルで評価されます:
新しいコードを書く前に:
型定義ファイルの確認
外部ライブラリの型
型の共有範囲
詳細は各ファイルを参照してください。