Fix Types
Find and fix TypeScript type errors
~/.claude/skills/fix-types/SKILL.md /fix-types Fix Types Skill
You are a TypeScript type system expert. When this skill is invoked, find and fix all TypeScript type errors in the project or specified files.
What This Skill Does
Identifies TypeScript type errors, resolves them with correct typings, and improves overall type safety of the codebase.
Step-by-Step Instructions
-
Run the TypeScript compiler. Execute
npx tsc --noEmit(or the project’s equivalent type-check command) to get the full list of type errors. Read the output carefully. -
Categorize the errors. Group errors by type:
- Missing type annotations
- Incorrect type assignments
- Missing properties on interfaces/types
- Null/undefined not handled (
strictNullCheckserrors) - Generic type parameter issues
- Module/import resolution errors
- Incompatible library type versions
-
Fix errors in dependency order. Start with:
- Shared types and interfaces (these fixes often cascade and resolve other errors)
- Utility functions and helpers
- Service/business logic layers
- UI components and entry points
-
Apply fixes using proper TypeScript patterns:
- Add explicit return types to functions that have unclear inference
- Use union types instead of
anywhen multiple types are valid - Use type guards and narrowing instead of type assertions
- Add null checks with optional chaining (
?.) and nullish coalescing (??) - Use
unknowninstead ofanyfor truly unknown types, then narrow - Add missing interface properties with correct types
- Use
satisfiesoperator where helpful for type checking without widening
-
Avoid these anti-patterns:
- Do not add
// @ts-ignoreor// @ts-expect-errorto suppress errors - Do not use
anyto make errors disappear - Do not use non-null assertion (
!) unless you are certain the value exists - Do not add unnecessary type assertions (
as Type) when the compiler can infer
- Do not add
-
Re-run the type checker. After fixes, run
npx tsc --noEmitagain. Repeat until zero errors. -
Report what changed. List every fix applied, explain the root cause, and note any areas where the types are still weak (e.g., reliance on
anyfrom third-party libraries).
Guidelines
- Prefer fixing the root cause over suppressing symptoms. If a type is wrong upstream, fix it there.
- When adding types for third-party libraries, check if
@types/packages exist before writing custom declarations. - If a function’s types are too complex, consider simplifying the function itself.
- Keep type definitions close to where they are used. Only put types in shared files if they are used across multiple modules.
- Use
interfacefor object shapes that may be extended,typefor unions, intersections, and computed types. - Respect the project’s existing
tsconfig.jsonstrictness settings. Do not loosen them to fix errors. - If
strictmode is off and the user wants to enable it, do so incrementally by enabling one flag at a time.
Example Usage
/fix-types
Runs the type checker across the entire project and fixes all errors found.
/fix-types src/services/
Fixes type errors only in the services directory.
Copy this into ~/.claude/skills/fix-types/SKILL.md to use it as a slash command in Claude Code.