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-types
3description: Extract shared type definitions into a dedicated types directory without runtime behavior changes
4type: execution
5version: v0.1
6required_conventions: [alignment-page]
7argument-hint: "[optional: package, app, directory, or domain to refactor]"
8metadata:
9 source: https://skillmd.com/skills/georgeqle/extract-shared-types
10---
11
12# Extract Shared Types
13
14Invoke as `$extract-shared-types`.
15
16Use 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.
17
18## Process
19
201. **Establish scope.**
21 - Read `$ARGUMENTS` for a package, app, directory, or domain.
22 - If no scope is provided, inspect the repo and choose the smallest coherent area with shared exported types.
23 - Read project instructions, package manifests, TypeScript config, path aliases, lint rules, package export maps, and existing `types/` or barrel conventions.
24
252. **Classify declarations before editing.**
26 - Candidate moves: exported `type` aliases, `interface` declarations, ambient declarations, generic helper shapes, DTO/result shapes, props/state shapes, and domain data shapes.
27 - 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.
28 - Treat TypeScript `enum` as runtime unless the project already uses `const enum` safely and the compiler settings make the move clearly type-only.
29
303. **Design the target type layout.**
31 - Create or reuse a dedicated `types/` directory at the nearest appropriate boundary.
32 - Organize files by domain, feature, or package convention rather than by source file name when a domain boundary is clear.
33 - 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.
34
354. **Move type declarations.**
36 - Move only the approved type declarations.
37 - Preserve exported names, generic parameters, comments that explain shape semantics, and public visibility.
38 - Keep runtime implementation files focused on runtime logic, importing moved declarations with `import type` where supported.
39
405. **Update imports and compatibility.**
41 - Update internal imports to the new type files.
42 - Use `import type` for type-only imports and avoid creating new value imports from `types/`.
43 - 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.
44 - Avoid widening public barrels unless the repo already exposes that type surface intentionally.
45
466. **Verify behavior preservation.**
47 - Run the narrowest relevant typecheck, tests, lint/import checks, and dependency-cycle checks available.
48 - Inspect the diff for runtime changes: implementation logic, emitted values, schema definitions, package exports, route behavior, and component behavior should not change.
49 - If verification fails, fix import/type issues without changing runtime behavior.
50
51## Output
52
53When reporting completion, include:
54
55- Scope refactored.
56- Type files created or reused.
57- Compatibility re-exports left in place, if any.
58- Verification commands run and their results.
59- Any skipped candidates with the reason they were runtime-coupled or public-API-sensitive.
60
61## Alignment Page
62
63Follow the shared alignment-page convention via the packaged convention resolver; output path is `alignment/extract-shared-types-{topic}.html`.
64
65## Constraints
66
67- Zero runtime behavior changes.
68- Do not move declarations unless they are type-only.
69- Do not introduce dependency upgrades, schema redesigns, or broad module restructuring.
70- Do not remove public import paths unless the user explicitly requests a breaking change.
71- Preserve unrelated user changes in the working tree.
72
73## Default Shipping Contract
74
75Follow the shared shipping contract convention in CLAUDE.md.
76