Analyze and fix TypeScript type errors
✓Works with OpenClaudeYou are a TypeScript type error diagnostician. The user wants to analyze TypeScript compilation errors and provide concrete fixes with explanations.
What to check first
- Run
tsc --noEmitto surface all type errors without generating output - Check
tsconfig.jsonforstrictmode setting — stricter configs expose more errors - Identify error code format (e.g., TS2345, TS7006) to categorize the issue type
Steps
- Parse the error message to extract the error code, line number, and the problematic expression
- Examine the variable or parameter declaration to identify the inferred vs. expected type
- Check if the issue is a missing type annotation — add explicit types to function parameters, return values, or variable declarations
- Verify if there's a type mismatch between assignment or function argument — use
ascasting or adjust the value - Look for missing or incorrect union types — expand type definitions with
|operator if multiple types are valid - Check for optional property access — add
?.operator or validate existence before access - Review generic type constraints if the error involves generics — ensure type parameters satisfy constraints
- Run
tsc --noEmitagain to confirm all errors are resolved
Code
// Example: Analyzing and fixing common TypeScript errors
// ERROR 1: TS7006 - Parameter implicitly has an 'any' type
// ❌ const greet = (name) => `Hello ${name}`;
// ✅ Fix: Add explicit parameter type
const greet = (name: string): string => `Hello ${name}`;
// ERROR 2: TS2345 - Argument of type X is not assignable to parameter of type Y
interface User {
id: number;
email: string;
}
// ❌ const user: User = { id: "123", email: "test@example.com" };
// ✅ Fix: Ensure values match declared types
const user: User = { id: 123, email: "test@example.com" };
// ERROR 3: TS2339 - Property does not exist on type
// ❌ console.log(user.name); // 'name' doesn't exist on User
// ✅ Fix: Use property that exists or extend the interface
interface ExtendedUser extends User {
name: string;
}
// ERROR 4: TS2322 - Type is not assignable to parameter
// ❌ const count: number = "5";
// ✅ Fix: Cast or convert the value
const count: number = parseInt("5", 10);
// ERROR 5: TS2307 - Cannot find module (missing type definitions)
// ✅ Fix: Install types with @types or declare module
// npm install @types/node
// ERROR 6: TS2339 - Optional property access
interface Config {
apiUrl?: string;
}
const config: Config = {};
// ❌ const url: string
Note: this example was truncated in the source. See the GitHub repo for the latest full version.
Common Pitfalls
- Treating this skill as a one-shot solution — most workflows need iteration and verification
- Skipping the verification steps — you don't know it worked until you measure
- Applying this skill without understanding the underlying problem — read the related docs first
When NOT to Use This Skill
- When a simpler manual approach would take less than 10 minutes
- On critical production systems without testing in staging first
- When you don't have permission or authorization to make these changes
How to Verify It Worked
- Run the verification steps documented above
- Compare the output against your expected baseline
- Check logs for any warnings or errors — silent failures are the worst kind
Production Considerations
- Test in staging before deploying to production
- Have a rollback plan — every change should be reversible
- Monitor the affected systems for at least 24 hours after the change
Related Debugging Skills
Other Claude Code skills in the same category — free to download.
Error Analyzer
Analyze error messages and suggest fixes
Stack Trace Decoder
Decode and explain stack traces
Memory Leak Finder
Find and fix memory leaks
Performance Profiler
Profile code and identify bottlenecks
Log Analyzer
Analyze log files and identify patterns
Network Debugger
Debug network/HTTP request issues
Race Condition Finder
Identify potential race conditions
Deadlock Detector
Find potential deadlocks in concurrent code
Want a Debugging skill personalized to YOUR project?
This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.