Typescript Refactoring Patterns

🌐Community
by autohandai · vlatest · Repository

Helps with TypeScript, refactoring, patterns as part of developing backend services and APIs workflows.

Install on your platform

We auto-selected Claude Code based on this skill’s supported platforms.

1

Run in terminal (recommended)

terminal
claude mcp add typescript-refactoring-patterns npx -- -y @trustedskills/typescript-refactoring-patterns
2

Or manually add to ~/.claude/settings.json

~/.claude/settings.json
{
  "mcpServers": {
    "typescript-refactoring-patterns": {
      "command": "npx",
      "args": [
        "-y",
        "@trustedskills/typescript-refactoring-patterns"
      ]
    }
  }
}

Requires Claude Code (claude CLI). Run claude --version to verify your install.

About This Skill

What it does

This skill assists with refactoring TypeScript code, focusing on common patterns and addressing potential code smells. It provides guidance on improving type safety and code structure through techniques like using discriminated unions, polymorphism, and branded types. The goal is to help developers write more maintainable and robust backend services and APIs.

When to use it

  • When encountering multiple boolean flags in your TypeScript code that could be refactored into a discriminated union.
  • When you have switch statements based on type properties, suggesting the application of a strategy pattern.
  • When needing to create reusable type guards for narrowing types.
  • To prevent "primitive obsession" and enforce validation using branded types.
  • During code reviews to identify and address common TypeScript code smells like overuse of any, non-null assertions, or excessive optional chaining.

Key capabilities

  • Type Narrowing Guidance: Recommends using type guards and discriminated unions over type assertions (as).
  • Const Assertions: Suggests utilizing as const for immutable literal types.
  • Generic Constraints: Encourages the use of extends constraints in generics instead of any.
  • Branded Types: Provides techniques for domain-specific validation using branded types.
  • Refactoring Patterns: Offers solutions for refactoring patterns like extracting discriminated unions, replacing conditionals with polymorphism, and creating reusable type guards.
  • Code Smell Detection: Identifies common TypeScript code smells (e.g., any types, non-null assertions) to guide improvements.

Example prompts

  • "How can I refactor this code snippet with multiple boolean flags into a discriminated union?"
  • "I have a switch statement based on type; what's the best way to refactor it?"
  • "Can you help me create a reusable type guard for checking if a value is not null or undefined?"

Tips & gotchas

  • Enable strict: true in your tsconfig.json file for optimal results and stricter type checking.
  • The skill focuses on refactoring patterns and code smells specific to TypeScript; it's not a general-purpose coding assistant.
  • Consider using satisfies for type checking without widening when appropriate.

Tags

🛡️

TrustedSkills Verification

Unlike other registries that point to live repositories, TrustedSkills pins every skill to a verified commit hash. This protects you from malicious updates — what you install today is exactly what was reviewed and verified.

Security Audits

Gen Agent Trust HubPass
SocketPass
SnykPass

Details

Version
vlatest
License
Author
autohandai
Installs
45

🌐 Community

Passed automated security scans.