技能 TypeScript Expert
📦

TypeScript Expert

低风险 ⚡ 包含脚本⚙️ 外部命令

掌握 TypeScript 开发,获得专家级指导

在复杂的 TypeScript 类型、构建性能或迁移挑战上遇到困难?从专业的 TypeScript 助手获得类型级编程、现代工具链和最佳实践的专家指导。

支持: Claude Codex Code(CC)
🥉 76 青铜
1

下载技能 ZIP

2

在 Claude 中上传

前往 设置 → 功能 → 技能 → 上传技能

3

开启并开始使用

测试它

正在使用“TypeScript Expert”。 我的函数参数一直出现 'implicit any' 错误

预期结果:

在 tsconfig.json 中启用 noImplicitAny。然后添加显式类型注解:function greet(name: string): string { return `Hello, ${name}`; }。对于复杂情况,使用 unknown 并缩小范围:function process(input: unknown) { if (typeof input === 'string') { /* input 现在是 string */ } }

正在使用“TypeScript Expert”。 如何防止混用 UserId 和 OrderId 字符串?

预期结果:

使用品牌类型:type Brand<K, T> = K & { readonly __brand: T }; type UserId = Brand<string, 'UserId'>; type OrderId = Brand<string, 'OrderId'>; 创建构造函数:const createUserId = (id: string): UserId => id as UserId; 这在编译时防止将 UserId 传递到需要 OrderId 的地方。

安全审计

低风险
v1 • 2/25/2026

Static analysis flagged 64 patterns but manual review confirms most are false positives. The backtick patterns are TypeScript template literal types and markdown code fences, not shell execution. URLs are JSON schema references. One legitimate finding: subprocess.run with shell=True in local diagnostic script uses only hardcoded commands with no user input injection risk. No network activity, credential access, or data exfiltration detected.

4
已扫描文件
1,016
分析行数
6
发现项
1
审计总数
中风险问题 (1)
Subprocess with shell=True
Python diagnostic script uses subprocess.run with shell=True which could enable command injection if user input reaches the command parameter. Review confirms all commands are hardcoded strings with no external input, making this safe for local diagnostic use.
低风险问题 (3)
False positive: Template literal types flagged as shell execution
Static analyzer incorrectly flagged TypeScript template literal types (e.g., `${infer T}`) in utility-types.ts as shell backtick execution. These are type-level string manipulation, not command execution.
False positive: Markdown code fences flagged as shell execution
Static analyzer incorrectly flagged markdown code fence delimiters (```typescript) in documentation as shell backtick execution. These are documentation formatting, not executable code.
False positive: JSON schema URL flagged as hardcoded network endpoint
The $schema reference to json.schemastore.org is a standard TypeScript configuration pattern for IDE autocomplete, not an active network request.

风险因素

⚡ 包含脚本
未记录任何特定位置
⚙️ 外部命令 (1)
审计者: claude

质量评分

68
架构
100
可维护性
87
内容
50
社区
79
安全
74
规范符合性

你能构建什么

企业级 TypeScript 迁移

通过增量策略、tsconfig 配置和类型注解模式,指导大规模 JavaScript 到 TypeScript 的迁移。

高级类型系统设计

使用条件类型和模板字面量类型设计复杂的泛型工具、领域建模的品牌类型和类型安全的 API。

构建性能优化

诊断缓慢的类型检查、配置增量构建并优化 monorepo TypeScript 项目引用。

试试这些提示

基础类型问题
我有一个 TypeScript 错误:[粘贴错误]。我的代码是:[粘贴代码]。这个错误是什么意思,我该如何修复?
类型配置审查
审查我的 tsconfig.json 的最佳实践:[粘贴配置]。对于 [库/应用] 项目,我应该更改哪些设置?
高级类型模式
我需要创建一个类型来 [描述需求]。例如,它应该 [给出示例]。你能使用 TypeScript 的类型系统设计这个吗?
迁移策略
我正在将一个 [规模] 的 JavaScript 代码库迁移到 TypeScript。我们使用 [工具/框架]。最好的增量方法是什么,我应该从哪些 tsconfig 设置开始?

最佳实践

  • 在 tsconfig.json 中启用 strict 模式和 noUncheckedIndexedAccess 以获得最大的类型安全性
  • 对于对象形状优先使用 interface 而不是 type,以获得更好的错误消息和声明合并
  • 使用 unknown 而不是 any 来保证类型安全,然后在使用值之前使用类型守卫进行缩小

避免

  • 使用 any 类型来绕过错误,而不是正确地为值添加类型
  • 过度使用类型断言(as Type)在没有正当理由的情况下绕过类型检查
  • 当更简单的解决方案可行时,使用复杂的泛型过度设计类型

常见问题

我应该使用 interface 还是 type 来定义对象形状?
对于对象形状优先使用 interface。interface 提供更好的错误消息,支持声明合并,并且可以扩展。对于联合类型、原始类型或需要 interface 不支持的类型功能时使用 type。
当文件存在时如何修复 'Cannot find module' 错误?
检查 moduleResolution 是否与你的打包器匹配(bundler 用于 Vite/esbuild,node16 用于 Node.js)。验证 tsconfig.json 中的 baseUrl 和 paths。对于 monorepo,确保配置了 workspace 协议。清除缓存:rm -rf node_modules/.cache .tsbuildinfo
unknown 和 any 之间有什么区别?
any 完全禁用类型检查。unknown 要求在使用之前缩小类型,保持类型安全。当你不知道类型时始终优先使用 unknown,然后使用 typeof、instanceof 或自定义类型守卫进行缩小。
如何从 JavaScript 增量迁移到 TypeScript?
首先在 tsconfig.json 中启用 allowJs 和 checkJs。逐步将文件重命名为 .ts,从隔离的模块开始。逐个文件添加类型。一次启用一个 strict 模式功能。使用 ts-migrate 或 AI 辅助进行批量类型注解。
为什么我的 TypeScript 编译如此缓慢?
在 tsconfig.json 中启用 skipLibCheck 和 incremental。使用精确的 include/exclude 模式。对于 monorepo,使用 composite 配置项目引用。运行 npx tsc --extendedDiagnostics 来识别瓶颈。考虑切换到 esbuild 或 swc 以获得更快的构建。
TypeScript 路径映射在运行时有效吗?
不,TypeScript 路径仅在编译时有效。对于运行时,使用带有 tsconfig-paths 的 ts-node,配置 Node.js 模块解析,或使用解析路径的打包器。在生产环境中,先编译以便路径在输出中被解析。