Extract Shared Types
Invoke as $extract-shared-types.
Use this skill for type hoisting, type barreling, shared types/ directories, import honesty, and circular-dependency prevention when the requested change is explicitly structural and behavior-preserving.
Process
Establish scope.
- Read
$ARGUMENTS for a package, app, directory, or domain.
- If no scope is provided, inspect the repo and choose the smallest coherent area with shared exported types.
- Read project instructions, package manifests, TypeScript config, path aliases, lint rules, package export maps, and existing
types/ or barrel conventions.
Classify declarations before editing.
- Candidate moves: exported
type aliases, interface declarations, ambient declarations, generic helper shapes, DTO/result shapes, props/state shapes, and domain data shapes.
- Do not move runtime values: functions, constants, classes, runtime enums, schemas, validators, database/API clients, React components, business logic, or anything imported as a value.
- Treat TypeScript
enum as runtime unless the project already uses const enum safely and the compiler settings make the move clearly type-only.
Design the target type layout.
- Create or reuse a dedicated
types/ directory at the nearest appropriate boundary.
- Organize files by domain, feature, or package convention rather than by source file name when a domain boundary is clear.
- Prefer direct imports from domain type files. Add
types/index.ts only if the project already uses barrels or repeated type imports would otherwise become noisy.
Move type declarations.
- Move only the approved type declarations.
- Preserve exported names, generic parameters, comments that explain shape semantics, and public visibility.
- Keep runtime implementation files focused on runtime logic, importing moved declarations with
import type where supported.
Update imports and compatibility.
- Update internal imports to the new type files.
- Use
import type for type-only imports and avoid creating new value imports from types/.
- If old import paths are part of a public API or package boundary, leave type-only re-exports from the original module rather than forcing a breaking migration.
- Avoid widening public barrels unless the repo already exposes that type surface intentionally.
Verify behavior preservation.
- Run the narrowest relevant typecheck, tests, lint/import checks, and dependency-cycle checks available.
- Inspect the diff for runtime changes: implementation logic, emitted values, schema definitions, package exports, route behavior, and component behavior should not change.
- If verification fails, fix import/type issues without changing runtime behavior.
Output
When reporting completion, include:
- Scope refactored.
- Type files created or reused.
- Compatibility re-exports left in place, if any.
- Verification commands run and their results.
- Any skipped candidates with the reason they were runtime-coupled or public-API-sensitive.
Alignment Page
Follow the shared alignment-page convention via the packaged convention resolver; output path is alignment/extract-shared-types-{topic}.html.
Constraints
- Zero runtime behavior changes.
- Do not move declarations unless they are type-only.
- Do not introduce dependency upgrades, schema redesigns, or broad module restructuring.
- Do not remove public import paths unless the user explicitly requests a breaking change.
- Preserve unrelated user changes in the working tree.
Default Shipping Contract
Follow the shared shipping contract convention in CLAUDE.md.
1---2name: extract-shared-types3description: Extract shared type definitions into a dedicated types directory without runtime behavior changes4---5
6# Extract Shared Types
7
8Invoke as `$extract-shared-types`.
9
10Use this skill for type hoisting, type barreling, shared `types/` directories, import honesty, and circular-dependency prevention when the requested change is explicitly structural and behavior-preserving.
11
12## Process
13
141. **Establish scope.**
15 - Read `$ARGUMENTS` for a package, app, directory, or domain.
16 - If no scope is provided, inspect the repo and choose the smallest coherent area with shared exported types.
17 - Read project instructions, package manifests, TypeScript config, path aliases, lint rules, package export maps, and existing `types/` or barrel conventions.
18
192. **Classify declarations before editing.**
20 - Candidate moves: exported `type` aliases, `interface` declarations, ambient declarations, generic helper shapes, DTO/result shapes, props/state shapes, and domain data shapes.
21 - Do not move runtime values: functions, constants, classes, runtime enums, schemas, validators, database/API clients, React components, business logic, or anything imported as a value.
22 - Treat TypeScript `enum` as runtime unless the project already uses `const enum` safely and the compiler settings make the move clearly type-only.
23
243. **Design the target type layout.**
25 - Create or reuse a dedicated `types/` directory at the nearest appropriate boundary.
26 - Organize files by domain, feature, or package convention rather than by source file name when a domain boundary is clear.
27 - Prefer direct imports from domain type files. Add `types/index.ts` only if the project already uses barrels or repeated type imports would otherwise become noisy.
28
294. **Move type declarations.**
30 - Move only the approved type declarations.
31 - Preserve exported names, generic parameters, comments that explain shape semantics, and public visibility.
32 - Keep runtime implementation files focused on runtime logic, importing moved declarations with `import type` where supported.
33
345. **Update imports and compatibility.**
35 - Update internal imports to the new type files.
36 - Use `import type` for type-only imports and avoid creating new value imports from `types/`.
37 - If old import paths are part of a public API or package boundary, leave type-only re-exports from the original module rather than forcing a breaking migration.
38 - Avoid widening public barrels unless the repo already exposes that type surface intentionally.
39
406. **Verify behavior preservation.**
41 - Run the narrowest relevant typecheck, tests, lint/import checks, and dependency-cycle checks available.
42 - Inspect the diff for runtime changes: implementation logic, emitted values, schema definitions, package exports, route behavior, and component behavior should not change.
43 - If verification fails, fix import/type issues without changing runtime behavior.
44
45## Output
46
47When reporting completion, include:
48
49- Scope refactored.
50- Type files created or reused.
51- Compatibility re-exports left in place, if any.
52- Verification commands run and their results.
53- Any skipped candidates with the reason they were runtime-coupled or public-API-sensitive.
54
55## Alignment Page
56
57Follow the shared alignment-page convention via the packaged convention resolver; output path is `alignment/extract-shared-types-{topic}.html`.
58
59## Constraints
60
61- Zero runtime behavior changes.
62- Do not move declarations unless they are type-only.
63- Do not introduce dependency upgrades, schema redesigns, or broad module restructuring.
64- Do not remove public import paths unless the user explicitly requests a breaking change.
65- Preserve unrelated user changes in the working tree.
66
67## Default Shipping Contract
68
69Follow the shared shipping contract convention in CLAUDE.md.
70