claude-code-framework/essential/skills/development/typescript-hardening/SKILL.md
Enforce strict TypeScript patterns that prevent runtime errors. Use when reviewing code for type safety, eliminating 'any' types, or setting up tsconfig for new projects. Triggers on "any type", "type error", "TypeScript strict", "type safety", "runtime error from types".
npx skillsauth add tokenized2027/claude-initilization-v7 typescript-hardeningInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Eliminate runtime type errors by enforcing strict TypeScript patterns across your codebase.
Every project must use this baseline:
{
"compilerOptions": {
"strict": true,
"noUncheckedIndexedAccess": true,
"noImplicitOverride": true,
"noPropertyAccessFromIndexSignature": true,
"exactOptionalPropertyTypes": true,
"forceConsistentCasingInFileNames": true,
"noFallthroughCasesInSwitch": true
}
}
Never trust external data. Validate at the boundary:
import { z } from 'zod'
// Define the schema
const ApiResponseSchema = z.object({
data: z.object({
price: z.number(),
volume: z.number(),
timestamp: z.string().datetime(),
}),
status: z.enum(['ok', 'error']),
})
type ApiResponse = z.infer<typeof ApiResponseSchema>
// Validate at the boundary
async function fetchPrice(endpoint: string): Promise<ApiResponse['data']> {
const raw = await fetch(endpoint).then(r => r.json())
const parsed = ApiResponseSchema.parse(raw) // Throws if invalid
return parsed.data
}
Replace boolean flags with discriminated unions:
// ❌ Bad: Multiple booleans create impossible states
interface BadState {
isLoading: boolean
isError: boolean
data: Data | null
error: Error | null
}
// ✅ Good: Each state is explicit and complete
type QueryState =
| { status: 'idle' }
| { status: 'loading' }
| { status: 'error'; error: Error }
| { status: 'success'; data: Data }
// Usage forces handling every case
function render(state: QueryState) {
switch (state.status) {
case 'idle': return <Placeholder />
case 'loading': return <Skeleton />
case 'error': return <ErrorDisplay error={state.error} />
case 'success': return <DataView data={state.data} />
}
}
// Make specific fields required from a partial type
type RequireFields<T, K extends keyof T> = T & Required<Pick<T, K>>
// Extract the resolved type of a Promise
type Awaited<T> = T extends Promise<infer U> ? U : T
// Safe record access
function getProperty<T extends Record<string, unknown>>(obj: T, key: string): unknown {
return obj[key] // noUncheckedIndexedAccess makes this `unknown`, not `T[string]`
}
| Banned Pattern | Replacement |
|---------------|-------------|
| any | unknown + type guard or Zod validation |
| as TypeName | Type guard function or Zod parse |
| ! (non-null assertion) | Optional chaining + nullish coalescing |
| @ts-ignore | Fix the actual type error |
| Object | Record<string, unknown> |
| Function | Specific function signature |
Find all violations in a codebase:
# Count 'any' types
grep -rn ': any' --include='*.ts' --include='*.tsx' src/ | wc -l
# Find ts-ignore comments
grep -rn '@ts-ignore\|@ts-expect-error' --include='*.ts' --include='*.tsx' src/
# Find non-null assertions
grep -rn '!\.' --include='*.ts' --include='*.tsx' src/ | grep -v 'node_modules'
# Find type assertions
grep -rn ' as ' --include='*.ts' --include='*.tsx' src/ | grep -v 'import'
✅ Use typescript-hardening when:
❌ Don't use for:
development
Methodical debugging using reproducible steps, instrumentation, and root-cause analysis. Use when something is broken and you don't know why. Triggers on "bug", "broken", "not working", "error", "fails intermittently", "regression", "unexpected behavior".
development
Optimize prompts for Claude Code agents, API calls, and multi-agent orchestration. Use when writing system prompts, agent instructions, or refining LLM interactions. Triggers on "improve prompt", "write a prompt", "agent instructions", "system prompt", "prompt not working", "LLM output quality".
tools
Structured ideation and design review before any creative or constructive work. Use before building features, components, architecture, dashboards, or automation workflows. Triggers on "plan this", "design this", "brainstorm", "think through", "what should we build", "how should I approach".
testing
Generates test files for components and functions with setup, basic tests, and mocks. Use when user says "add tests", "create test", "test this component", or mentions testing.