---
name: typescript-type-refactoring-tool
description: "Applies a mechanical refactor across TypeScript type definitions: renames by pattern, strips deprecated members, injects generic parameters, and lists every edit so the review is a diff check, not a hunt. Use when existing TypeScript types need a bulk rename, deprecated members removed, or a generic parameter threaded through, with every change itemised. Do not use for redesigning types for stronger safety, inferring types from data, or writing documentation. Related topics: coding, typescript."
---

# TypeScript Type Refactoring Tool

Applies a mechanical refactor across TypeScript type definitions: renames by pattern, strips deprecated members, injects generic parameters, and lists every edit so the review is a diff check, not a hunt.

## When to use

Use this skill when existing TypeScript types need a bulk rename, deprecated members removed, or a generic parameter threaded through, with every change itemised. Do not use it for redesigning types for stronger safety, inferring types from data, or writing documentation.

## Workflow

1. Ask the user for each input listed below in a single message, skipping any they have already given. Where options are listed, offer them, but accept other answers too.
2. Apply renames to the chosen declaration kinds and update every reference in the supplied source so nothing dangles.
3. Remove members marked @deprecated and list borderline cases for a decision instead of removing them.
4. Add the generic parameters with defaults where given and thread them to the members that should use them; untouched usages still compile.
5. Apply the export style and output location, preserving comments and formatting as requested.
6. Check for dangling references, name collisions, and removed members still extended, and list them as blockers in the summary.

## Inputs

- **Source** (longer free text)
- **Declaration kinds to touch** (choose any: Interface, Type alias, Enum, Class)
- **Rename pattern** (free text, e.g. "prefix every name with Api")
- **Remove deprecated members** (choose one: Yes, No)
- **Generic parameters to add** (free text, e.g. "TPayload with a default of unknown")
- **Keep comments** (choose one: Yes, No)
- **Export style** (choose one: named, default, none)
- **Output location** (free text, e.g. "src/types/refactored")

## Output

A markdown document with Refactored Types (one TypeScript code block per file) and Change Summary (one bullet per change with old and new form, blockers last).

## Prompt template

Fill the inputs into this template and follow it as the full instruction.

### TypeScript Type Refactoring Tool

Apply the refactor specified below to the type definitions and report every change.

- Source: {{Source}}
- Declaration kinds to touch: {{Declaration kinds to touch}}
- Rename pattern: {{Rename pattern}}
- Remove deprecated members: {{Remove deprecated members}}
- Generic parameters to add: {{Generic parameters to add}}
- Keep comments: {{Keep comments}}
- Export style: {{Export style}}
- Output location: {{Output location}}

Apply the changes in a fixed order so they do not interfere: renames first, then member removal, then generics, then export changes. Rename only declarations of the chosen kinds and update every reference to them inside the supplied source, including type references in other declarations, so the result compiles. Treat a member as deprecated only when it carries a @deprecated JSDoc tag or a comment that says so; list anything borderline instead of guessing. When adding a generic parameter, give it a default where one is specified so existing usages without arguments still compile, and thread it to the members that should use it. Preserve formatting and comments where possible; drop comments only when asked.

Check the result for references that now point nowhere, duplicate names from a rename collision, and members removed that other declarations still extend. Report those as blockers rather than silently fixing them.

### Output
Return a markdown document with two sections: Refactored Types, with the updated definitions in a TypeScript code block per file under the output location, and Change Summary, one bullet per modification naming the declaration, the old form, and the new form, with blockers listed last.

## Pitfalls

- Renaming a declaration without updating the references inside other declarations, so the output fails to compile.
- Removing a member that is not tagged @deprecated because its name looks old, which deletes live API surface.
- Adding a generic parameter without a default, which breaks every existing usage that passes no type argument.
