Instructions
Help the user migrate a React/Next.js codebase from JavaScript to strict TypeScript.
Before edits: suggest pnpm exec tsc --noEmit (or npx tsc --noEmit) so there is a baseline.
When to Use
- Use for JS→strict TypeScript or type audits.
- Prefer
code-assistantfor small non-migration diffs. - Prefer
testing-agentto lock behavior before refactors.
Mode A - full file refactor
- Ensure
tsconfig.jsonhas"strict": true(and"noImplicitAny": trueif split). - Rename target
.js/.jsx→.ts/.tsxone module at a time (smallest leaf first). - Infer props and state; add explicit return types on exported functions and hooks.
- Replace
anywithunknown, generics, or narrow types; use type guards where needed. - For large repos, optional ts-morph codemods - list files touched.
- Update imports and
package.jsontypes field if missing. - Re-run
tsc --noEmitand fix errors until clean for touched scope.
Mode B - audit only
- Scan
src/for.js/.jsxremaining. - Report
file:linefor: implicitany, missing return types,@ts-ignore, unsafe casts. - Prioritize entry points and shared utilities.
- No file writes - deliver a markdown table grouped by severity.
Outcomes
- Mode A: converted files + strict config +
tsc --noEmitinstructions. - Mode B: prioritized audit report with estimated effort per file.
Output Rules
State mode. List files changed or audited. Include the exact tsc command used.
Scope and boundaries
- In scope: TypeScript migration, typing, strict config for frontend/Next repos.
- Out of scope: backend language migrations, changing runtime behavior beyond types, mass delete/refactor without user scope.
Safety
- Mode A modifies source files; user should commit first and run
tsc --noEmitbefore applying. - Do not print
.envvalues; do not run destructive shell without user approval. - Match the project lockfile (
pnpm-lock.yaml→ pnpm).
Troubleshooting
- RSC errors after rename: ensure server files avoid client-only APIs; add
"use client"only where hooks are required. anyexplosion: narrow one module at a time; usesatisfiesand discriminated unions before generics everywhere.- ts-morph version mismatch: align
typescriptdevDependency with the project’s installed version.
Related skills
code-assistant- scoped TS fixestesting-agent- type-safe testspr-review-workflow- review type migrations
GitHub: https://github.com/bh611627/skillcodex/tree/main/skills/typescript-refactor/SKILL.md
npm: https://www.npmjs.com/package/@skillcodex/skills