---
name: TypeScript Expert
slug: typescript-expert
category: AI Engineering
description: TypeScript Expert provides guidance on TypeScript type system patterns, async handling, and React conventions. Use it when writing or reviewing TypeScript code and tests.
github: "https://github.com/val1813/kwcode/tree/master/kaiwu/builtin_experts/typescript"
language: Python
stars: 688
forks: 92
install: "npx degit https://github.com/val1813/kwcode/tree/master/kaiwu/builtin_experts/typescript ~/.claude/skills/typescript"
installs_to: ~/.claude/skills/typescript
source_path: kaiwu/builtin_experts/typescript/SKILL.md
collection_size: 19
category_size: 2451
collection_url: "https://dirskills.com/collections/val1813/kwcode"
added: 2026-08-12T04:43:51.524Z
last_synced: 2026-08-12T04:43:51.524Z
canonical_url: "https://dirskills.com/skills/typescript-expert"
---

# TypeScript Expert

TypeScript Expert provides guidance on TypeScript type system patterns, async handling, and React conventions. Use it when writing or reviewing TypeScript code and tests.

**Install:**

```bash
npx degit https://github.com/val1813/kwcode/tree/master/kaiwu/builtin_experts/typescript ~/.claude/skills/typescript
```

## README

## 领域知识

你是TypeScript专家。

### 类型系统
- 优先使用 `interface` 定义对象形状，`type` 用于联合/交叉/映射类型
- 避免 `any`，使用 `unknown` + 类型守卫
- 善用泛型约束：`<T extends Base>`
- 使用 `as const` 创建字面量类型
- 条件类型和映射类型用于高级类型编程

### 异步模式
- 优先 `async/await`，避免裸 Promise 链
- 错误处理用 try/catch 包裹 await
- 并行操作用 `Promise.all()`，需要容错用 `Promise.allSettled()`
- 避免在循环中 await（用 `Promise.all(items.map(...))` 替代）

### React 规范（如适用）
- 函数组件 + Hooks，不用 class 组件
- 自定义 Hook 以 `use` 开头
- 状态管理：简单用 useState，复杂用 useReducer
- 副作用在 useEffect 中，注意依赖数组
- 避免不必要的 re-render：useMemo, useCallback

### 项目结构
- `src/` 放源代码
- `src/types/` 或 `src/@types/` 放类型定义
- 配置文件：`tsconfig.json`（严格模式推荐）
- 测试：Jest + `@testing-library/react`

### 测试
- 运行测试：`npx jest --ci`
- 测试文件：`*.test.ts` 或 `*.spec.ts`
- Mock：`jest.mock()` 或 `vi.mock()`（Vitest）
- 类型测试：`tsd` 或 `expect-type`

## 经验规则（自动生成）
