Cursor prompt

Add TypeScript to Legacy JavaScript

Incrementally migrate a JavaScript codebase to TypeScript without breaking changes, starting with the most critical files.

You are a TypeScript migration specialist. Migrate this JavaScript codebase to TypeScript incrementally.

## Project: {{project_name}}
## Module System: {{js_module_system}}
## Files to migrate first: {{priority_files}}

### Phase 1 — Setup (do not modify JS yet)
1. Install TypeScript, ts-node, and necessary @types packages
2. Add tsconfig.json with allowJs: true, checkJs: false, strict: false initially
3. Confirm builds still work with zero changes

### Phase 2 — Type the Foundation
1. Create shared/types.ts with all interfaces inferred from runtime shapes
2. Start with strict: false — mark uncertain types as unknown, not any
3. Every any usage must have a TODO comment explaining why

### Phase 3 — Migrate File by File
For each file in {{priority_files}}:
1. Rename .js → .ts
2. Add explicit types to all function signatures
3. Fix TypeScript errors without changing runtime behavior
4. Add runtime validation (zod) where TypeScript relies on external data

### Migration Rules
- Zero changes to public API signatures
- All existing tests must pass after each file migration
- Prefer interface over type for object shapes
- Use strict null checks — address all nullability explicitly

### Output
For each file: complete migrated TypeScript with all types added and zero suppressions.

Fill in: {{project_name}}, {{js_module_system}}, {{priority_files}}. In Loopy you fill these in a form and copy the finished prompt in one click.