TypeScript 专家

AI 代码审查 TypeScript

diffray 理解 TypeScript。泛型、严格模式、类型守卫——AI 驱动的审查,打造类型安全的应用程序。

Node.js18+
Deno1.x
Bun1.x
NestJS10.x
tRPC10+

为 TypeScript 开发者打造

深度理解 TypeScript 类型系统的 AI 代理。

类型安全

捕获类型错误,验证泛型,并执行严格模式模式。

  • 严格空值检查
  • 泛型约束
  • 类型收窄

运行时安全

发现编译器遗漏但会导致运行时错误的问题。

  • 类型断言滥用
  • 隐式 any
  • 不安全转换

安全性

检测全栈 TypeScript 应用程序中的安全漏洞。

  • 输入验证
  • SQL 注入
  • XSS 防护

性能

识别类型级别的性能问题和构建优化问题。

  • 复杂类型
  • Bundle 影响
  • Tree shaking

我们检测到的常见 TypeScript 问题

类型断言 (as any)
绕过类型安全,运行时错误
标记不安全转换,建议类型守卫
缺少空值检查
Cannot read property of undefined
验证 strictNullChecks 模式
泛型中的隐式 any
类型信息丢失,bug
强制显式泛型约束
不安全的类型谓词
错误的类型收窄
验证用户定义的类型守卫

类型安全的自定义规则

执行团队的 TypeScript 标准。禁止不安全模式,要求严格类型。

  • 禁止 'as any' 和不安全的类型断言
  • 要求导出的显式返回类型
  • 对 ID 执行品牌类型
  • 验证 Zod/io-ts schema 使用
.diffray/rules/typescript.yaml
rules:
  - id: ts_no_unsafe_any
    agent: bugs
    title: No unsafe type assertions
    description: Avoid 'as any' and prefer
      type guards or unknown
    importance: 9
    match:
      file_glob:
        - '**/*.ts'
        - '**/*.tsx'
    checklist:
      - No 'as any' assertions
      - Use type guards for narrowing
      - Prefer unknown over any
    tags:
      - typescript
      - type-safety
      - strict-mode

TypeScript 常见问题

构建类型安全的应用

加入使用 diffray 进行专家 AI 代码审查的 TypeScript 团队。

严格模式验证
泛型检查
类型守卫验证