Agent skill
retrofitting-types
Add types to untyped code gradually without breaking functionality
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/other/other/retrofitting-types
SKILL.md
Skill: retrofitting-types
What I do
I help you add type safety to existing JavaScript or other untyped codebases. I focus on an incremental approach that enhances code quality without requiring a complete rewrite. I ensure that you can transition your project to TypeScript safely and effectively.
When to use me
- When you're migrating a JavaScript project to TypeScript.
- When you're adding types to an existing API or library.
- When you're trying to improve code readability and maintainability.
- When you're working with legacy code that has many untyped variables or functions.
Core principles
- Incremental typing, add types at module boundaries first to get the most immediate benefit.
- Strictness as a goal, start with a permissive configuration and gradually enable stricter rules.
- Avoid any, use
unknownor more specific types to catch real errors. - Leverage inference, let the type system infer types when possible to reduce boilerplate.
Patterns & examples
Boundary typing
Focus on function signatures and external API calls.
- Pattern, Define an interface for the incoming data and the return value of a function.
TypeScript migration path
Follow a step-by-step approach to add types.
- Step 1, Enable
allowJsandcheckJsin yourtsconfig.json. - Step 2, Add
@ts-checkto the top of your JavaScript files. - Step 3, Gradually rename files to
.tsand add explicit types.
Using unknown over any
Provide more safety when the type is truly unknown.
function processData(input: unknown) {
if (typeof input === 'string') {
console.log(input.toUpperCase());
}
}
Type definitions for 3rd-party JS
Create custom .d.ts files for libraries that lack them.
- Action, Define the main functions and objects exported by the library.
Anti-patterns to avoid
- ❌ Type assertion abuse, using
as Typetoo frequently to silence compiler errors. - ❌ Excessive any usage, using
anyeverywhere defeats the purpose of adding types. - ❌ The "Rewrite" trap, attempting to rewrite the whole codebase at once instead of incremental improvement.
- ❌ Ignoring inference, manually typing every single variable even when the compiler can infer them.
KB Reference
~/vaults/baphled/3. Resources/Knowledge Base/AI Development System/Skills/Code-Quality/Retrofitting Types.md
Related skills
javascript, for the core language expertise.clean-code, for maintaining high quality during the transition.refactor, for restructuring code to be more type-friendly.static-analysis, for finding issues during the migration.
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?