Typescript Refactoring Patterns
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.
Run in terminal (recommended)
claude mcp add typescript-refactoring-patterns npx -- -y @trustedskills/typescript-refactoring-patterns
Or manually add to ~/.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
switchstatements 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 constfor immutable literal types. - Generic Constraints: Encourages the use of
extendsconstraints in generics instead ofany. - 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.,
anytypes, 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: truein yourtsconfig.jsonfile 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
satisfiesfor 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 Hub | Pass |
| Socket | Pass |
| Snyk | Pass |
🌐 Community
Passed automated security scans.