Typescript Refactoring Patterns
ListedHelps with TypeScript, refactoring, patterns as part of developing backend services and APIs workflows.
Install on your platform
Showing Claude Code. One command installs this skill into any of the agents below.
- 1
Run this in your project
terminal$ npx skills add autohandai/community-skills --skill typescript-refactoring-patterns -a claude-code Uses the open-source
skillsCLI and needs Node.js. Add-gto install it for your user instead of this project.
What we know about this skill
Publisher
autohandai
Taken from the source listing. We haven't verified who controls this account.
Install target
Live repository
Not pinned. Installing fetches whatever the repository holds at the time you run the command.
Automated safety checks
We could not read this skill's source, so none of the checks below were run.
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.