All skills
Skillintermediate
/migrate-file - Migrate JS to TypeScript
Convert a JavaScript file to TypeScript with proper type annotations.
Claude Code Knowledge Pack7/10/2026
Overview
/migrate-file - Migrate JS to TypeScript
Convert a JavaScript file to TypeScript with proper type annotations.
Steps
- Read the target JavaScript file and understand its structure
- Rename the file from .js to .ts (or .jsx to .tsx for React components)
- Add TypeScript configuration if tsconfig.json does not exist
- Infer types from usage patterns: variable assignments, function parameters, return values
- Add explicit type annotations to function parameters and return types
- Convert require/module.exports to import/export syntax
- Add interface definitions for object shapes used in the file
- Replace
anytypes with specific types wherever inferable - Handle common patterns: callbacks, promises, event handlers
- Fix type errors reported by the TypeScript compiler
- Add JSDoc-compatible type comments where types are complex
- Run the TypeScript compiler in strict mode and report remaining issues
Rules
- Enable strict mode in tsconfig.json for maximum type safety
- Use interfaces for object shapes, type aliases for unions and primitives
- Prefer unknown over any for truly unknown types
- Add null checks where variables could be null or undefined
- Convert dynamic property access to typed alternatives
- Keep the same file structure and logic; only add types
- Do not change runtime behavior during migration