Use Claude to Fix TypeScript Strict Mode Violations
Enabling "strict": true in tsconfig.json often unleashes hundreds of errors at once — paste them in batches and let Claude work through them systematically rather than one agonising error at a time.
# Get your full error list first
npx tsc --noEmit 2>&1 | head -100 | claude -p "Fix all these TypeScript strict mode violations. For each one, explain the root cause and show the corrected code."
Rather than wrestling with cryptic messages, Claude explains the root cause and applies the right fix — whether that's adding type guards, replacing any with meaningful types, or handling possibly-null access:
// Before (strict mode violation — Object is possibly 'undefined')
function getUser(id: string) {
const user = users.find(u => u.id === id);
return user.name;
}
// After (Claude's fix)
function getUser(id: string): string {
const user = users.find(u => u.id === id);
if (!user) throw new Error(`User ${id} not found`);
return user.name;
}
For any types specifically, ask Claude to infer proper types from how the variable is actually used throughout your codebase — it's far more accurate than guessing manually.
You can also ask Claude to enable strict mode incrementally: turn on one flag at a time (like noImplicitAny first, then strictNullChecks) and fix each batch before moving on.
Strict mode is painful to enable on existing codebases — Claude turns a multi-week migration into an afternoon.
Log in to leave a comment.
The /security-review command scans your uncommitted changes for injection vectors, auth gaps, hardcoded secrets, and other common vulnerabilities.
The SessionStart hook fires when any session begins or resumes, making it ideal for loading environment variables and running one-time setup scripts.
Ask Claude to write property-based tests for your functions using fast-check — it identifies the mathematical invariants in your code and generates tests that cover inputs you'd never enumerate by hand.