TypeScript type safety patterns and best practices for maximum type coverage. Triggers: 型安全, type safety, any, unknown, 型推論, 型ガード, type guard, discriminated union, 判別可能なUnion, strictNullChecks, 型定義, 型カバレッジ, TypeScript, 暗黙のany, implicit any, 型アサーション, type assertion.
/plugin marketplace add thkt/claude-config/plugin install complete-workflow-system@thkt-development-workflowsThis skill is limited to using the following tools:
references/strict-mode.mdreferences/type-coverage.mdreferences/type-guards.mdTarget: Maximum type safety with minimal type gymnastics.
| Context | Target | Warning |
|---|---|---|
| Type coverage | 95%+ | < 90% |
| Any usage | 0 (justified only) | > 5 instances |
| Type assertions | Minimal | > 10 instances |
| Implicit any | 0 | Any > 0 |
| Strict mode | All enabled | Any disabled |
| Section | File | Focus | Triggers |
|---|---|---|---|
| Coverage | references/type-coverage.md | Explicit types, avoiding any | any, unknown, 型カバレッジ |
| Guards | references/type-guards.md | Narrowing, discriminated unions | 型ガード, type guard |
| Strict | references/strict-mode.md | tsconfig, React types | strictNullChecks, React |
any without explicit justificationis functions)neveras)strictNullChecks: truenoImplicitAny: truestrictFunctionTypes: true| Principle | Application |
|---|---|
| Fail Fast | Catch errors at compile-time, not runtime |
| Let TS Infer | Don't over-type what's already clear |
| Types as Docs | Good types serve as documentation |
| Prefer unknown | Use unknown over any for safer handling |
function isSuccess<T>(response: Response<T>): response is SuccessResponse<T> {
return response.success === true
}
type Action =
| { type: 'INCREMENT'; payload: number }
| { type: 'DECREMENT'; payload: number }
| { type: 'RESET' }
// Exhaustive check
function reducer(action: Action): number {
switch (action.type) {
case 'INCREMENT': return action.payload
case 'DECREMENT': return -action.payload
case 'RESET': return 0
default:
const _exhaustive: never = action
return _exhaustive
}
}
interface SelectProps<T> {
value: T
options: T[]
onChange: (value: T) => void
}
function Select<T>({ value, options, onChange }: SelectProps<T>) { /* ... */ }
applying-code-principles - General code quality principlesgenerating-tdd-tests - Type-safe test patternstype-safety-reviewer - Primary consumer of this skill