Skill Code Quality

Fix Types

Find and fix TypeScript type errors

install path ~/.claude/skills/fix-types/SKILL.md
command /fix-types
typescripttypestype-safetytype-errors
SKILL.md

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

  1. 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.

  2. Categorize the errors. Group errors by type:

    • Missing type annotations
    • Incorrect type assignments
    • Missing properties on interfaces/types
    • Null/undefined not handled (strictNullChecks errors)
    • Generic type parameter issues
    • Module/import resolution errors
    • Incompatible library type versions
  3. 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
  4. Apply fixes using proper TypeScript patterns:

    • Add explicit return types to functions that have unclear inference
    • Use union types instead of any when multiple types are valid
    • Use type guards and narrowing instead of type assertions
    • Add null checks with optional chaining (?.) and nullish coalescing (??)
    • Use unknown instead of any for truly unknown types, then narrow
    • Add missing interface properties with correct types
    • Use satisfies operator where helpful for type checking without widening
  5. Avoid these anti-patterns:

    • Do not add // @ts-ignore or // @ts-expect-error to suppress errors
    • Do not use any to 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
  6. Re-run the type checker. After fixes, run npx tsc --noEmit again. Repeat until zero errors.

  7. 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 any from 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 interface for object shapes that may be extended, type for unions, intersections, and computed types.
  • Respect the project’s existing tsconfig.json strictness settings. Do not loosen them to fix errors.
  • If strict mode 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.

get crystl