change_signature_by_tsmorph
Add, remove, or reorder parameters in a function and automatically update all call sites across the project using type-checked refactoring.
Instructions
[ts-morph] Add, remove, or reorder parameters of a function/method/arrow-function and propagate the matching argument changes to every call site in the project.
When to use
Adding a required parameter to a function with many callers (LLM single-edit reliably misses some — this tool guarantees every call site is updated via the type checker).
Removing or reordering parameters of a function that is imported, re-exported, or accessed through a method chain.
Inserting a context-like first parameter (
ctx,logger, etc.) into existing helpers.
When NOT to use
Renaming a parameter — use
rename_symbol_by_tsmorphon the parameter identifier instead.Changing only the parameter's type annotation without changing arity — edit the source file directly.
Moving the function to another file — use
move_symbol_to_file_by_tsmorph.
Critical constraints
positionmust point at the function's name identifier (1-based line/column). Forconst foo = () => {}, point atfoo; forclass C { foo() {} }, point atfoo.functionNamemust match the identifier text at that position (sanity check).All paths (
tsconfigPath,targetFilePath) MUST be absolute.Spread arguments (
fn(...args)) at call sites cause the operation to fail when a change would modify arguments. Refactor those callers manually first, or limit changes to trailing optional/defaulted parameters with noargumentForCallers.Operations apply sequentially; later operations see the parameter list produced by earlier ones.
Operation semantics
add: Inserts a parameter at
index(default: end). IfargumentForCallersis provided, that exact text is inserted at the same index in every call site. If omitted, callers are left untouched (use only for trailing optional / defaulted parameters).remove: Removes the parameter at
index. Each call site with at least that many arguments drops the corresponding one. Calls passing fewer arguments are left untouched.reorder: Rebuilds the parameter list and every call site according to
newOrder. Fails if any call site does not pass exactly that many arguments (no way to safely reorder omitted optionals).
Tips
Run with
dryRun: truefirst when the function has many callers to preview the impacted files.For adding multiple parameters at once, list multiple
addoperations; theirindexvalues refer to the parameter list after prior operations in the same call have been applied.
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 function declaration. | |
| position | Yes | Exact position of the function name identifier. | |
| functionName | Yes | Name of the function/method at that position. | |
| changes | Yes | Ordered list of signature operations to apply. See the tool description for semantics. | |
| dryRun | No | If true, only show intended changes without modifying files. |