typescript-general-guidelines

typescript-general-guidelines is a cursor rule for coding agents from holtwood/awesome-cursorrules-zh. It costs 756 tokens per session, scanned A, original, MIT.

A set of general rules for writing TypeScript code and tests. It covers naming, types, functions, error handling, data structures, and test organization.

In plain words
What is it for?
Use it when creating or reviewing TypeScript files, public APIs, classes, functions, and their unit or acceptance tests.
Why use it?
It gives a project consistent coding conventions, making code easier to read, review, and maintain across contributors.

Cursor rule

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/holtwood/awesome-cursorrules-zh/typescript-general-guidelines
Clone the repo
git clone --depth 1 https://github.com/holtwood/awesome-cursorrules-zh

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for typescript-general-guidelines

README.md
[![agentmods](https://agentmods.dev/badge/rules/holtwood/awesome-cursorrules-zh/typescript-general-guidelines.svg)](https://agentmods.dev/rules/holtwood/awesome-cursorrules-zh/typescript-general-guidelines)
Your own site
<a href="https://agentmods.dev/rules/holtwood/awesome-cursorrules-zh/typescript-general-guidelines"><img src="https://agentmods.dev/badge/rules/holtwood/awesome-cursorrules-zh/typescript-general-guidelines.svg" alt="Measured on agentmods" height="20"></a>
Per session 756 This file is loaded in full into every session.
When invoked 756 The same file — it is already loaded in full.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00756 $0.00756
Opus 5 $0.00378 $0.00378
Sonnet 5 $0.00151 $0.00151
Haiku 4.5 $0.00076 $0.00076

Measured 5d ago against content hash 2ea803dbdd27, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

typescript-general-guidelines scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 5d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

docs/rules/backend/nodejs/nestjs-typescript/typescript-general-guidelines.mdc · 67 lines

What it actually says

  • 对所有代码和文档使用英语。
  • 始终声明每个变量和函数的类型(参数和返回值)。
  • 避免使用 any。
  • 创建必要的类型。
  • 使用 JSDoc 记录公共类和方法。
  • 不要在函数内留空行。
  • 每个文件一个导出。
  • 对类使用 PascalCase。
  • 对变量、函数和方法使用 camelCase。
  • 对文件和目录名使用 kebab-case。
  • 对环境变量使用 UPPERCASE。
  • 避免魔法数字并定义常量。
  • 每个函数以动词开头。
  • 对布尔变量使用动词。例如:isLoading、hasError、canDelete 等。
  • 使用完整单词而不是缩写,并正确拼写。
    • 除了标准缩写如 API、URL 等。
    • 除了众所周知的缩写:
      • i、j 用于循环
      • err 用于错误
      • ctx 用于上下文
      • req、res、next 用于中间件函数参数
  • 编写具有单一目的的短函数。少于 20 条指令。
  • 用动词和其他内容命名函数。
  • 如果返回布尔值,使用 isX 或 hasX、canX 等。
  • 如果不返回任何内容,使用 executeX 或 saveX 等。
  • 通过以下方式避免嵌套块:
    • 早期检查和返回。
    • 提取到工具函数。
  • 使用高阶函数(map、filter、reduce 等)避免函数嵌套。
  • 对简单函数(少于 3 条指令)使用箭头函数。
  • 对非简单函数使用命名函数。
  • 使用默认参数值而不是检查 null 或 undefined。
  • 使用 RO-RO 减少函数参数
    • 使用对象传递多个参数。
    • 使用对象返回结果。
    • 为输入参数和输出声明必要的类型。
  • 使用单一抽象级别。
  • 不要滥用原始类型,将数据封装在复合类型中。
  • 避免在函数中进行数据验证,使用具有内部验证的类。
  • 优先使用数据的不可变性。
  • 对不变的数据使用 readonly。
  • 对不变的字面量使用 as const。
  • 遵循 SOLID 原则。
  • 优先使用组合而不是继承。
  • 声明接口来定义合约。
  • 编写具有单一目的的小类。
    • 少于 200 条指令。
    • 少于 10 个公共方法。
    • 少于 10 个属性。
  • 使用异常处理你不期望的错误。
  • 如果你捕获异常,应该是为了:
    • 修复预期的问题。
    • 添加上下文。
    • 否则,使用全局处理器。
  • 对测试遵循 Arrange-Act-Assert 约定。
  • 清楚地命名测试变量。
  • 遵循约定:inputX、mockX、actualX、expectedX 等。
  • 为每个公共函数编写单元测试。
  • 使用测试替身模拟依赖项。
    • 除了执行成本不高的第三方依赖项。
  • 为每个模块编写验收测试。
  • 遵循 Given-When-Then 约定。
Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 5d ago First seen · 67 lines · 756 tokens per session scan A 2ea803dbdd27

Subscribe to this mod's changes

typescript-general-guidelines is a cursor rule published in the GitHub repository holtwood/awesome-cursorrules-zh (232 stars, last pushed 1mo ago), licensed MIT. It adds 756 tokens to every session, about $0.0038 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.