提示词库

JavaScript提示词

用于 JavaScript 和 TypeScript 的提示词:给无类型代码添加类型、理清 Promise,以及解释不熟悉的模块。

提示词是英文的,即它们的编写和测试所用的语言。这些页面上的说明和指引已翻译。

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

把 JavaScript 转换为 TypeScript

在不改变行为的前提下给 JavaScript 模块添加类型,并列出无法加上类型的地方。

适用场景: 逐个文件把模块迁移到 TypeScript,并且需要结果能在 strict 模式下编译通过时。

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>

变量

{{module}}
要转换的 JavaScript 源码。

示例输入

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

示例输出

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

仅为示意:为展示预期的形式而编写,并非由模型生成。

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

解释不熟悉的模块

说明模块做什么、输入输出是什么,以及修改它时哪里有风险。

适用场景: 你接手了代码,需要在编辑之前先理解它。

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>

变量

{{module}}
模块源码。

示例输入

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

示例输出

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

仅为示意:为展示预期的形式而编写,并非由模型生成。

改成你的

修改需求以符合你的标准,然后检查结果。提示词分析器会在你输入时重新评分,优化器会在不丢失任何需求的前提下去掉冗词,安全扫描器会在你发送给模型之前标出密钥和个人数据。

更多类别