Prompt library

JavaScript prompts

Prompts for JavaScript and TypeScript: adding types to untyped code, untangling promises, and explaining unfamiliar modules.

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

Convert JavaScript to TypeScript

Adds types to a JavaScript module without changing its behavior, and lists what it could not type.

Use it when: Migrating a module to TypeScript one file at a time and you need the result to compile under strict mode.

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>

Variables

{{module}}
The JavaScript source to convert.

Example input

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

Example output

```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.

Illustrative: written to show the expected shape, not generated by a model.

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

Explain an unfamiliar module

Explains what a module does, its inputs and outputs, and where it is risky to change.

Use it when: You inherited code and need to understand it before you edit it.

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>

Variables

{{module}}
The module source.

Example input

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

Example output

## 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 |

Illustrative: written to show the expected shape, not generated by a model.

Make it yours

Edit the requirements to match your standards, then check the result. Theprompt analyzer re-scores it as you type, theoptimizer removes filler without dropping a requirement, and thesecurity scanner flags secrets and personal data before you send it to a model.

More categories