P
BeginnerChatGPT

Convert a JavaScript File to TypeScript

Converts JavaScript code to TypeScript with strict types, typing choice explanations, tsconfig configuration and progressive migration plan for a larger codebase.

Paste in your AI

Paste this prompt in ChatGPT, Claude or Gemini and customize the variables in brackets.

Tu es un expert TypeScript. Aide-moi à migrer ce code JavaScript vers TypeScript de façon progressive et pragmatique.

**Framework :** [FRAMEWORK] (ex: React, Node.js, Express)
**Niveau de rigueur TypeScript souhaité :** [NIVEAU_RIGUEUR] (strict, modéré, progressif)
**Librairies utilisées :** [LIBRAIRIES]

**Code JavaScript à convertir :**
```javascript
[CODE_JAVASCRIPT]
```

Fournis :
1. **Code TypeScript** : version convertie avec types explicites
2. **Choix de types** : explication des décisions de typage (interface vs type, génériques utilisés)
3. **`any` utilisés** : liste des endroits où tu as dû utiliser `any` et comment les éliminer à terme
4. **Configuration tsconfig.json** : options recommandées pour ce projet
5. **Dépendances @types** : packages DefinitelyTyped à installer
6. **Pièges de migration** : erreurs courantes avec ce type de code JS
7. **Plan de migration progressive** : si le fichier s'intègre dans une codebase plus large

Principe : préférer les types stricts mais rester pragmatique.

Why this prompt works

Requesting typing choice explanations transforms the conversion into TypeScript training. The list of residual any with elimination plan is honest: a complete migration without any is often unrealistic in one pass. The adapted tsconfig avoids integration problems in an existing project.

Use Cases

Progressively migrating a React JS codebase to TSAdding TypeScript to an existing Node.js projectTraining a team on TypeScript with real code

Expected Output

Converted TypeScript code, typing choice explanations, residual any list, tsconfig.json, @types dependencies, migration pitfalls and progressive migration plan.

Learn more

Check the full skill on Prompt Guide to master this technique from A to Z.

View on Prompt Guide

📬 Get new prompts every week

Join our newsletter and never miss a prompt.