📘Cursor
Cursor TypeScript 严格模式规则
TypeScript 项目启用严格模式的编码规则。
#cursor#typescript#严格模式
Cursor TypeScript 严格模式规则
配置要求
- strict: true
- noUncheckedIndexedAccess: true
- exactOptionalPropertyTypes: true
类型定义
- 优先使用 interface 而不是 type
- 联合类型使用 type
- 避免 any,使用 unknown
泛型
- 泛型参数使用 T 或完整单词
- 约束使用 extends
- 工具类型优先于手写
最佳实践
- 使用 const 断言
- 使用 satisfies 操作符
- 枚举使用 const enum