ts-morph-refactor

Automate TypeScript refactoring with ts-morph AST manipulation across multiple files.

114|24|Updated Feb 13, 2025
One-click install
npx skills add https://github.com/dafthunk-com/dafthunk --skill ts-morph-refactor
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: ts-morph-refactor
Source: https://github.com/dafthunk-com/dafthunk/tree/main/.claude/skills/ts-morph-refactor
Command: npx skills add https://github.com/dafthunk-com/dafthunk --skill ts-morph-refactor

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires ts-morph, and includes scripts (resource) components.

What problem does it solve?

ts-morph-refactor provides a set of executable scripts to perform AST-based refactoring across a TypeScript codebase, ensuring safe, consistent updates.

Core Features & Use Cases

  • Rename symbols across files using semantic rename with ts-morph.
  • Move declarations between files while updating imports.
  • Propagate interface/class changes to all implementations.
  • Add methods to implementations and modify parameter/return types across codebase.

Quick Start

Run the appropriate script (e.g., rename-symbol.ts) to apply a semantic refactor across your TypeScript project.

Frequently Asked Questions about ts-morph-refactor

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I rename TypeScript symbols across multiple files safely?

TypeScript interface propagation applies AST-based refactoring to update all implementations when an interface or class changes. By analyzing the syntax tree, it automatically modifies implementing classes to match the updated contract.

What is the best way to move TypeScript declarations between files?

Before applying TypeScript refactoring changes, you can use the dry-run preview feature. This shows exactly what modifications the AST manipulation will make across your files, allowing you to verify updates before committing.

Do I need a TypeScript project setup to use ts-morph for refactoring?

After completing an AST-based TypeScript refactor, you should run a type-check. This validates that the semantic changes, such as moved declarations or propagated interfaces, did not introduce type errors across the codebase.

Can AST refactoring add methods to TypeScript class implementations?

AST refactoring can add methods to TypeScript class implementations across your codebase. By leveraging ts-morph, it programmatically inserts methods into target classes and modifies parameter or return types consistently.