Skip to content

commandFrontendtypescript

Convert to TypeScript

Converts a JavaScript file to TypeScript with real types and no any shortcuts, and keeps the build and tests passing.

npx workspacetemplates add convert-to-typescript --tool claude-code

Writes 1 file to .claude/commands/

.claude/commands/convert-to-typescript.md15 lines · 1.1 KBFile
---
description: Converts a JavaScript file to TypeScript with real types and no any shortcuts, and keeps the build and tests passing.
argument-hint: "[file or folder to convert]"
---

Convert to TypeScript: $ARGUMENTS

1. Read the target file and everything that imports it. Check `tsconfig.json` for `strict`, `allowJs` and path aliases, and follow the strictness already set.
2. Rename with `git mv` so history follows (`.js` to `.ts`, `.jsx` to `.tsx`).
3. Derive types from real usage: read call sites, tests and JSON shapes. Prefer `interface` or `type` for domain objects, union types for fixed options, generics for containers, and `unknown` plus narrowing for untrusted input.
4. Never write `any`, `as any` or `@ts-ignore`. Use `@ts-expect-error` with a reason only where a library type is wrong, and report each one.
5. Add types for dependencies from `@types/*` when missing, but ask before installing.
6. Fix real bugs the compiler exposes in a separate list, not silently.

Run `tsc --noEmit` and the tests. Report the new types, the remaining suppressions, and any bug found. Do not convert other files unless asked.

What it does

A rename from .js to .ts only moves the errors around. This command reads how the code is used, writes types that describe actual values, and avoids `any` and blanket casts that silence the compiler without helping.

It works on one file or folder at a time, so each conversion is a small change you can review.

Example

you › /convert-to-typescript src/utils/cart.js

agent › Renamed to cart.ts. Added CartItem and Discount types, a union for DiscountKind, and made applyDiscount generic over the item.
Found a bug: totals() reads item.qty but callers pass quantity. Not changed, flagged.
tsc --noEmit and jest pass. 0 uses of any.

Questions

Will it just add any everywhere?
No. The prompt forbids any and ts-ignore, and uses unknown with narrowing for anything it cannot prove.
What about bugs the compiler finds?
Findings from the compiler come as their own list, leaving the choice to you rather than changing behavior during a type conversion.
  • A11y Check

    CommandFrontend

    Free
  • Add Form Validation

    CommandFrontend

    Free
  • Add Loading States

    CommandFrontend

    Free
  • Check Responsive

    CommandFrontend

    Free