P
BeginnerChatGPT

Convert a JavaScript file to TypeScript

Converts JavaScript code to TypeScript with strict types, explanations of typing choices, 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

The request for 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 configuration avoids integration problems in an existing project.

Use Cases

Progressively migrate a React JS codebase to TSAdd TypeScript to an existing Node.js projectTrain a team on TypeScript with real code

Expected Output

TypeScript converted code, typing choice explanations, list of residual `any`, 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