Ask Claude to Add TypeScript Types to Your Untyped JavaScript Code
Migrating from JavaScript to TypeScript doesn't have to be a big-bang rewrite. Claude reads your JS files and adds types based on how the code is actually used.
"Add TypeScript types to src/services/userService.js — rename it to .ts and type everything"
Claude reads the function signatures, return values, object shapes, and how other files call it, then adds accurate types:
// Before: untyped JavaScript
function getUser(id) {
return db.query('SELECT * FROM users WHERE id = ?', [id]);
}
// After: Claude adds types from actual usage
interface User {
id: number;
name: string;
email: string;
created_at: Date;
}
async function getUser(id: number): Promise<User | null> {
return db.query<User>('SELECT * FROM users WHERE id = ?', [id]);
}
You can migrate incrementally:
# Start with the most important files
"Type the files in src/services/ — these are the core business logic"
# Type one module at a time
"Add types to the authentication module, including the middleware and helpers"
# Type API boundaries first
"Add TypeScript interfaces for all API request and response shapes"
# Generate types from API responses
"Read the API routes and generate TypeScript types for every endpoint's input and output"
Claude handles the nuances that make manual typing tedious:
- Union types — detects when a value can be
string | nullorUser | undefined - Generics — adds proper generic parameters to utility functions and collections
- External libraries — uses
@types/*packages and suggests installing missing ones - Gradual migration — uses
// @ts-ignoreoranysparingly where strict typing would require larger refactors - Discriminated unions — creates proper tagged union types for state machines and action objects
For existing TypeScript projects with loose types, Claude tightens them:
"Find all uses of 'any' in the codebase and replace them with proper types"
TypeScript migration is a typing problem — and Claude is very good at typing.
via Claude Code
Log in to leave a comment.
Set up Claude Code as an automated reviewer in your CI pipeline — on every pull request, it reads the diff, checks for bugs, security issues, missing tests, and convention violations, then posts its findings as a PR comment. Your human reviewers get a head start because the obvious issues are already flagged before they look.
Before deploying, tell Claude to read your project — migrations, environment variables, queue workers, scheduled tasks, caching, third-party integrations — and generate a deployment checklist that's specific to your app. Not a generic "did you run migrations?" list, but one that knows YOUR infrastructure and catches the things YOUR deploy can break.
Instead of writing a README from memory or copying a template, tell Claude to read your project and generate one that's actually accurate — real setup instructions from your config, real architecture from your directory structure, real API examples from your routes, and real prerequisites from your dependency files.