rename_symbol_by_tsmorph
Renames any TypeScript or JavaScript symbol across the entire project by resolving all references via the type checker, ensuring safe and complete renaming.
Instructions
[ts-morph] Type-aware rename of a TypeScript/JavaScript symbol (function, variable, class, type, interface, enum, etc.) across the entire project.
When to use
Renaming any symbol that may be imported, re-exported, or referenced in other files.
Prefer this over manual Edit + grep / sed. Identifier-based search misses re-exports, JSX attribute usage, and matches unrelated same-name tokens. This tool resolves references via the type checker, so it is both safer and faster.
Even for a "local-only" symbol, this tool is the correct default: it costs nothing extra and guarantees no missed reference.
When NOT to use
Renaming a file or folder (and updating imports to it) -> use
rename_filesystem_entry_by_tsmorph.Moving a symbol to a different file -> use
move_symbol_to_file_by_tsmorph.Just looking up where a symbol is used (no rename) -> use
find_references_by_tsmorph.
Critical constraints
positionmust point at the symbol's identifier (1-based line/column, as shown by editors). If the position lands on whitespace or a different token, the rename fails.symbolNamemust match the identifier text at that position; it is used as a sanity check.All paths (
tsconfigPath,targetFilePath) MUST be absolute.
Tips
Run with
dryRun: truefirst when the change spans many files, to preview the affected file list.
Result
Returns the list of modified (or to-be-modified, in dryRun) file paths, plus status and processing time.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| tsconfigPath | Yes | Path to the project's tsconfig.json file. | |
| targetFilePath | Yes | Path to the file containing the symbol to rename. | |
| position | Yes | The exact position of the symbol to rename. | |
| symbolName | Yes | The current name of the symbol. | |
| newName | Yes | The new name for the symbol. | |
| dryRun | No | If true, only show intended changes without modifying files. |