---
name: typescript-type-analyzer
description: "Maps every type in a TypeScript codebase into a machine-readable inventory: members, extends and implements links, and a plain summary, so you can see the shape of the code before refactoring it. Use when you need an inventory of every interface, type alias, enum, and class in TypeScript code and how they extend or reference each other, as JSON. Do not use for generating new types, documenting types for readers, or changing any of the declarations. Related topics: coding, typescript."
---

# TypeScript Type Analyzer

Maps every type in a TypeScript codebase into a machine-readable inventory: members, extends and implements links, and a plain summary, so you can see the shape of the code before refactoring it.

## When to use

Use this skill when you need an inventory of every interface, type alias, enum, and class in TypeScript code and how they extend or reference each other, as JSON. Do not use it for generating new types, documenting types for readers, or changing any of the declarations.

## 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. Record each declaration of the chosen kinds with name, kind, file, export status, generics, and members at the requested detail level.
3. Classify each type alias by shape (object, union, intersection, mapped, conditional, primitive) so consumers know how it can be used.
4. Capture every extends, implements, reference, and union-membership link between declarations as a relationship entry.
5. Build the inheritance tree when requested and flag cycles and unreferenced types as cleanup candidates.
6. Write the summary with counts per kind, the most-referenced types, and any duplicate shapes, then validate the JSON parses.

## Inputs

- **TypeScript source** (longer free text)
- **File paths covered** (free text, e.g. "src/models/*.ts")
- **Include types from external modules** (choose one: Yes, No)
- **Detail level** (choose one: Summary, Full, Debug)
- **Show inheritance tree** (choose one: Yes, No)
- **Declaration kinds to include** (choose any: Interface, Type alias, Enum, Class, Namespace)

## Output

One JSON object with 2-space indentation and the keys types, relationships, and summary, with nothing before or after it.

## Prompt template

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

### TypeScript Type Analyzer

Inventory every type declaration in the code below and how the types relate.

- TypeScript source: {{TypeScript source}}
- File paths covered: {{File paths covered}}
- Include types from external modules: {{Include types from external modules}}
- Detail level: {{Detail level}}
- Show inheritance tree: {{Show inheritance tree}}
- Declaration kinds to include: {{Declaration kinds to include}}

Walk the source file by file and record each declaration of the chosen kinds with its name, kind, file, export status, generic parameters, and members (name, type as written, optional, readonly). For type aliases, classify the shape: object, union, intersection, mapped, conditional, or primitive alias. Record every relationship: extends, implements, type references between declarations, and union membership. Resolve references to external modules only when asked; otherwise mark them as external by name.

At Summary level, keep members to a count; at Full, list them; at Debug, also include the source position and the raw text of each declaration. When the inheritance tree is requested, build it from the extends and implements links and flag cycles or types that nothing references, since those are the first candidates for cleanup. Write the summary last: how many declarations of each kind, the most-referenced types, and anything that looks like a duplicate shape under two names.

### Output
Return a JSON object with 2-space indentation and three top-level keys: "types" (array of declaration objects), "relationships" (array of links with from, to, and kind), and "summary" (a short plain-text overview). Nothing outside the JSON.

## Pitfalls

- Expanding types from node_modules when external modules were excluded, which buries the project's own types in noise.
- Treating a type reference inside a member as an extends link, which draws an inheritance tree that does not exist.
- Emitting a trailing comma or a comment inside the JSON, so the tool consuming the report fails to parse it.
