Cursor rule
.cursor/rules/ts.mdcCursor rules
Quality
44/100
Scores the file, not the repository.Length
133 words
8 headings · 0 code blocksRepository
1
— · pushed 337 days agoLast changed
3 days ago
First indexed 3 days ago.123456---78description: 现代 Web 开发的 TypeScript 编码标准与最佳实践9globs: **/\*.ts, **/_.tsx, \*\*/_.d.ts1011---1213# TypeScript 最佳实践1415## 类型系统1617- 对象定义时优先使用接口(`interface`)而非类型别名(`type`)18- 联合类型、交叉类型及映射类型使用`type`声明19- 避免使用`any`,未知类型优先使用`unknown`20- 启用严格的 TypeScript 配置(`strict: true`)21- 善用 TypeScript 内置的工具类型(如`Partial`、`Readonly`、`Pick`等)22- 可复用的类型模式使用泛型(`generics`)实现2324## 命名规范2526- 类型名与接口名使用帕斯卡命名法(PascalCase,如`UserModel`)27- 变量与函数名使用小驼峰命名法(camelCase,如`userName`)28- 常量使用全大写下划线命名法(UPPER_CASE,如`MAX_RETRY_TIMES`)29- 使用描述性名称并搭配辅助动词(如`isLoading`表示加载状态,`hasError`表示错误状态)30- React 组件 props 接口前缀统一为`Props`(如`ButtonProps`)3132## 代码组织3334- 类型定义尽量靠近其使用位置35- 共享类型通过独立类型文件导出(如`types/user.ts`)36- 使用索引导出(`index.ts`)统一管理文件导出37- 共享类型集中存放在`types`目录下38- 组件 props 与其组件文件放在一起(如`Button.tsx`中直接定义`ButtonProps`)3940## 函数规范4142- 公共函数显式声明返回类型(避免隐式`any`)43- 回调函数与方法使用箭头函数(保持`this`上下文一致性)44- 自定义错误类型实现精细化错误处理45- 复杂类型场景使用函数重载(`overloads`)46- 优先使用`async/await`而非 Promise 链4748## 核心原则4950- `tsconfig.json`中启用严格模式(`strict: true`)51- 不可变属性使用`readonly`修饰52- 使用可辨识联合类型(Discriminated Unions)保障类型安全53- 运行时类型检查使用类型守卫(`type guards`)54- 实现严谨的空值校验(避免`undefined`/`null`遗漏)55- 非必要不使用类型断言(`as`),优先通过类型守卫明确类型5657## 错误处理5859- 业务相关错误使用自定义错误类型(如`ApiError`、`ValidationError`)60- 可能失败的操使用`Result`类型封装(如`{ success: boolean; data?: T; error?: Error }`)61- 实现错误边界(Error Boundaries)捕获组件层异常62- `try-catch`块中使用类型化`catch`子句(明确捕获错误的类型)63- 正确处理 Promise 拒绝(`unhandledrejection`事件监听)6465## 设计模式6667- 复杂对象创建使用构建器模式(Builder Pattern)68- 数据访问层实现仓储模式(Repository Pattern)69- 对象创建使用工厂模式(Factory Pattern)70- 依赖管理采用依赖注入(Dependency Injection)71- 封装逻辑使用模块模式(Module Pattern)72
Also in lzyyzznl/all_in_one_search
Diff this repo’s formatsOne repository carrying more than one format is the comparison this product exists for: does anyone actually write different content in each file, or is one a copy of the other?
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| lzyyzznl/all_in_one_search.cursor/rules/clean-code.mdc · 1 | Cursor rules | no sections | 30/100 | 3 days ago | |
| lzyyzznl/all_in_one_search.cursor/rules/common.mdc · 1 | Cursor rules | no sections | 50/100 | 3 days ago | |
| lzyyzznl/all_in_one_search.cursor/rules/git.mdc · 1 | Cursor rules | typesgit | 58/100 | 3 days ago | |
| lzyyzznl/all_in_one_search.cursor/rules/quality-rule.mdc · 1 | Cursor rules | no sections | 30/100 | 3 days ago | |
| lzyyzznl/all_in_one_search.cursor/rules/tailwind.mdc · 1 | Cursor rules | ui | 44/100 | 3 days ago | |
| lzyyzznl/all_in_one_search.cursor/rules/vue.mdc · 1 | Cursor rules | typesapiui | 44/100 | 3 days ago |
Similar configs
Same format, overlapping stack, ranked by quality.
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| hiromaily/go-crypto-wallet.cursor/rules/typescript.mdc · 126 | Cursor rules | setupbuildtestlint-format+6 | 100/100 | 3 days ago | |
| TechSquidTV/Hermes.cursor/rules/10-hermes-api.mdc · 45 | Cursor rules | testlint-formatstylearch+5 | 100/100 | 3 days ago | |
| markstev/mark-starter.cursor/rules/frontend.mdc · 0 | Cursor rules | setuptestlint-formatstyle+6 | 99/100 | 3 days ago | |
| Allymahmoud/case-intake-platform.cursor/rules/frontend.mdc · 0 | Cursor rules | setuptestlint-formatstyle+7 | 99/100 | 3 days ago | |
| dodgecfr/combatfilms-webapp.cursor/rules/frontend.mdc · 0 | Cursor rules | setuptestlint-formatstyle+7 | 99/100 | 3 days ago | |
| deifos/clipmira-subtitles.cursor/rules/frontend.mdc · 1 | Cursor rules | setuptestlint-formatstyle+7 | 99/100 | 3 days ago | |
| langflow-ai/langflow.cursor/rules/docs_development.mdc · 153k | Cursor rules | setupbuildtestlint-format+7 | 97/100 | 3 days ago | |
| TechSquidTV/Hermes.cursor/rules/20-hermes-api-tests.mdc · 45 | Cursor rules | teststyletesting-strategysecurity+3 | 97/100 | 3 days ago |
