Agent skill
typescript-refactor
Safely refactor TypeScript code while maintaining type safety and test coverage. Includes verification steps.
Install this agent skill to your Project
npx add-skill https://github.com/cpa03/blueprintify/tree/main/.opencode/skill/typescript-refactor
SKILL.md
TypeScript Refactor Skill
Safely refactor TypeScript code with full verification.
Pre-Refactor Checklist
-
Run current tests to establish baseline:
bashnpm run test -
Run type check:
bashnpm run typecheck -
Note current state as baseline
Refactoring Patterns
Extract Function
// Before
function process(data: Data) {
// complex validation logic
if (!data.field1) throw new Error("field1 required");
if (!data.field2) throw new Error("field2 required");
// ... more processing
}
// After
function validateData(data: Data): void {
if (!data.field1) throw new Error("field1 required");
if (!data.field2) throw new Error("field2 required");
}
function process(data: Data) {
validateData(data);
// ... more processing
}
Extract Component (React)
// Before: Large component with repeated patterns
// After: Smaller, focused components with clear props
Rename Symbol
# Find all usages first
grep -r "oldName" --include="*.ts" --include="*.tsx" src/
Post-Refactor Verification
-
Run type check:
bashnpm run typecheck -
Run tests:
bashnpm run test -
Run linter:
bashnpm run lint -
Build project:
bashnpm run build
Rules
- Never change behavior during refactor
- One refactor type at a time
- Commit after each successful refactor
- If tests fail, rollback immediately
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
ci-pipeline-update
Updates CI/CD pipelines for DevOps Engineer
obra-superpowers-test-driven-development
Use when implementing any feature or bugfix, before writing implementation code
obra-superpowers-using-git-worktrees
Use when starting feature work that needs isolation from current workspace or before executing implementation plans - creates isolated git worktrees with smart directory selection and safety verification
react-component-create
Create new React components following project patterns and best practices. Includes proper typing, testing, and documentation.
madappgang-claude-code-debugging-strategies
Universal debugging strategies and techniques applicable across all technology stacks. Use when approaching unknown bugs or need language-agnostic debugging methodology.
resilience-check
Checklist for reliability engineering
Didn't find tool you were looking for?