
Field Mapping Safety
当重构涉及字段映射(dataIndex、枚举映射、类型转换)时触发。防止字段名推测错误,确保字段映射的正确性。
Install
npx skills add doccker/cc-use-exp --skill field-mapping-safety -g -a claude-code -y- Repository
- doccker/cc-use-exp1.1k
- Category
- Engineering
- Updated
- 2mo ago
- License
- See repository
- Context cost
- Mediumabout 1,655 tokens
- Runs scripts
- No, instructions only
What it does
当重构涉及字段映射(dataIndex、枚举映射、类型转换)时触发。防止字段名推测错误,确保字段映射的正确性。
字段映射安全规范
触发场景
- 重构表格列定义(dataIndex、columns)
- 重构枚举类型映射(typeMap、statusMap)
- 重构数据转换逻辑(render 函数、formatter)
- 类型定义中有多个相似字段(changedAt vs createdAt)
核心原则
不要根据类型定义推测字段名,必须查看原始代码的实际使用
检查清单
1. 字段名验证
- 查看原始代码的 dataIndex
- 查看后端 API 返回的实际字段名
- 优先使用必填字段,避免可选字段
- 注意字段名的细微差异(changedAt vs createdAt、changeType vs operationType)
2. 枚举映射验证
- 对照原始代码,逐个检查枚举值
- 确保映射完整(不遗漏任何枚举值)
- 检查枚举值的拼写(UPLOAD vs Upload)
- 检查枚举值的颜色、文本是否一致
3. 运行时测试
- TypeScript 类型检查通过(必要但不充分)
- 在实际环境中测试功能
- 检查是否显示 "Invalid Date"、"undefined"、空白
- 检查枚举值是否都有对应的映射
常见陷阱
陷阱 1: 类型定义有歧义
场景:类型定义中有多个相似字段
interface InvoiceHistory {
changedAt?: string // 可选字段
createdAt: string // 必填字段
changeType?: string // 错误字段
operationType: string // 正确字段
}
错误做法:
// ❌ 根据类型定义推测,选择了可选字段
dataIndex: 'changedAt' // 可能为 undefined → Invalid Date
dataIndex: 'changeType' // 字段不存在 → 显示为空
正确做法:
// ✅ 查看原始代码的实际使用
git show HEAD~1:src/components/InvoiceHistoryTab.tsx
// 原始代码使用 createdAt(必填)和 operationType(正确)
dataIndex: 'createdAt'
dataIndex: 'operationType'
陷阱 2: 枚举映射不完整
场景:重构时遗漏部分枚举值
错误做法:
// ❌ 只保留了 3 个类型
typeMap: {
CREATE: { text: '创建', color: 'green' },
UPDATE: { text: '更新', color: 'blue' },
DELETE: { text: '删除', color: 'red' },
}
正确做法:
// ✅ 查看原始代码,确保完整
git show HEAD~1:src/components/InvoiceHistoryTab.tsx
