Prompt-Bibliothek

JavaScript-Prompts

Prompts für JavaScript und TypeScript: Typen zu untypisiertem Code hinzufügen, Promises entwirren und unbekannte Module erklären.

Die Prompts sind auf Englisch, der Sprache, in der sie geschrieben und getestet wurden. Beschreibungen und Hinweise auf diesen Seiten sind übersetzt.

  • typescript
  • migration
  • types
100/100 · 144 Tokens

JavaScript in TypeScript umwandeln

Fügt einem JavaScript-Modul Typen hinzu, ohne sein Verhalten zu ändern, und listet auf, was sich nicht typisieren ließ.

Einsetzen, wenn: Beim Migrieren eines Moduls nach TypeScript Datei für Datei, wenn das Ergebnis im Strict-Modus kompilieren muss.

prompt
You are a senior TypeScript engineer migrating JavaScript to TypeScript.

## Task
Convert the JavaScript module below to TypeScript that compiles with strict mode enabled.

## Requirements
- Do not change runtime behavior, names, or exports.
- Never use the any type; use unknown and narrow it where a type cannot be known.
- Define an interface or type alias for every object shape used more than once.
- Add explicit return types to every exported function.

## Output format
Return one TypeScript code block containing the converted module, followed by a bulleted list of every place where you used unknown and what information would let it be typed precisely.

## Input
<module>
{{module}}
</module>

Variablen

{{module}}
Der umzuwandelnde JavaScript-Quellcode.

Beispieleingabe

module: a utils.js file exporting formatPrice(amount, currency) and parseOrder(json).

Beispielausgabe

```ts
export function formatPrice(amount: number, currency: string): string { ... }
export function parseOrder(json: string): Order { ... }
```
- `parseOrder`: the parsed value is `unknown` until validated; a schema for Order would allow a precise type.

Beispielhaft: geschrieben, um die erwartete Form zu zeigen, nicht von einem Modell erzeugt.

  • code reading
  • onboarding
  • documentation
100/100 · 171 Tokens

Ein unbekanntes Modul erklären

Erklärt, was ein Modul tut, seine Ein- und Ausgaben und wo eine Änderung riskant ist.

Einsetzen, wenn: Sie haben Code geerbt und müssen ihn verstehen, bevor Sie ihn bearbeiten.

prompt
You are a senior JavaScript engineer explaining code to a colleague who is new to the codebase.

## Task
Explain what the module below does and how to change it safely.

## Requirements
- Describe only what the code does; do not guess at intent that the code does not show.
- List every exported function with its parameters, return value, and side effects.
- Name the 3 places where a change is most likely to break callers, and say why.
- Use plain language and define any term a new team member may not know.

## Output format
Return markdown with three sections: What it does (at most 4 sentences), Exports (a table with the columns Name, Parameters, Returns, and Side effects), and Risky to change (numbered list).

## Input
<module>
{{module}}
</module>

Variablen

{{module}}
Der Quellcode des Moduls.

Beispieleingabe

module: a cache.js file that wraps fetch with an in-memory Map and a TTL.

Beispielausgabe

## What it does
Wraps `fetch` so repeated GET requests within 60 seconds return a stored response...

## Exports
| Name | Parameters | Returns | Side effects |
|---|---|---|---|
| cachedFetch | url, options | Promise<Response> | Writes to the module-level Map |

Beispielhaft: geschrieben, um die erwartete Form zu zeigen, nicht von einem Modell erzeugt.

Machen Sie ihn zu Ihrem

Passen Sie die Anforderungen an Ihre Standards an und prüfen Sie dann das Ergebnis. Der Prompt-Analyzer bewertet neu, während Sie tippen, der Optimierer entfernt Füllwörter, ohne eine Anforderung zu verlieren, und der Sicherheitsscanner markiert Geheimnisse und personenbezogene Daten, bevor Sie den Prompt an ein Modell senden.

Weitere Kategorien