Ask Claude to Add Type Annotations to Your Untyped Code for Better Safety and Autocompletion
Adding types to a codebase that grew up without them is tedious but valuable — better autocompletion, earlier bug detection, and self-documenting code. Claude can do the grunt work by reading how your code is actually used and inferring the right types.
> add TypeScript types to all the functions in src/utils/ —
> infer types from usage, don't use 'any'
Claude reads each function, traces how it's called throughout the codebase, looks at what values get passed in and returned, and adds precise type annotations — not just slapping any on everything but actually figuring out the real types.
This works across languages:
> add Python type hints to the functions in app/services/
> — use modern syntax (str | None instead of Optional[str])
> add PHPDoc type annotations to all methods in app/Repositories/
> — include @param, @return, and @throws
> add JSDoc types to the functions in lib/ so VS Code
> can provide autocompletion without switching to TypeScript
Claude infers types that a human would have to trace manually:
- Return types — reads every return path to determine what the function actually returns
- Parameter types — checks call sites to see what values are passed in
- Nullable types — detects when values can be null based on conditional checks in the code
- Generic types — recognizes collections and maps the element types from usage
- Union types — identifies when a parameter accepts multiple types
For gradual TypeScript migration, Claude can convert one file at a time:
> convert src/utils/formatting.js to TypeScript — rename to .ts,
> add types, and update the imports in files that reference it
Claude renames the file, adds types, updates import paths across the codebase, and fixes any type errors that surface — all in one pass.
Types are documentation that the compiler enforces — let Claude add them so you get the safety without the tedium.
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.