$ recombobulate _
home / tips / use-claude-to-fix-typescript-strict-mode-violations
0

Use Claude to Fix TypeScript Strict Mode Violations

bagwaa @bagwaa · Mar 25, 2026 · Workflows
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.

~/recombobulate $ tip --comments --count=0

Log in to leave a comment.

~/recombobulate $ tip --related --limit=3
0
Scan Pending Changes for Security Issues with /security-review

The /security-review command scans your uncommitted changes for injection vectors, auth gaps, hardcoded secrets, and other common vulnerabilities.

bagwaa @bagwaa · 1 hour ago
0
Run Setup Scripts on Every Session with the SessionStart Hook

The SessionStart hook fires when any session begins or resumes, making it ideal for loading environment variables and running one-time setup scripts.

bagwaa @bagwaa · 1 hour ago
0
Write Property-Based Tests with fast-check and Claude

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.

bagwaa @bagwaa · 2 hours ago