/field-mapping-safety
当重构涉及字段映射(dataIndex、枚举映射、类型转换)时触发。防止字段名推测错误,确保字段映射的正确性。
$ npx -y skills add doccker/cc-use-exp --skill field-mapping-safety --agent claude-codeHow it fires
How this skill gets triggered: by you, by Claude, or both.
- Fires itselfAuto-invocation. Claude auto-loads it when your prompt matches the work.Auto-invocation is when the right skill fires by itself at the right moment, driven by a FLOW.md router and a hook, instead of you invoking it by name. It is the difference between a skill being installed and a skill actually getting used.Read the full definition →
- You can call itInvoke it directly when you want it.
- Slash command
/field-mapping-safety
Context preview
The summary Claude sees to decide when to auto-load this skill.
当重构涉及字段映射(dataIndex、枚举映射、类型转换)时触发。防止字段名推测错误,确保字段映射的正确性。
SKILL.md
field-mapping-safety.SKILL.mdname: field-mapping-safety
description: 当重构涉及字段映射(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
// 原始代码有 10 个类型
typeMap: {
UPLOAD: { text: '上传发票', color: 'blue' },
OCR_START: { text: '开始OCR', color: 'cyan' },
OCR_SUCCESS: { text: 'OCR成功', color: 'green' },
OCR_FAILED: { text: 'OCR失败', color: 'red' },
OCR_RETRY: { text: '重试OCR', color: 'orange' },
MANUAL_EDIT: { text: '手动编辑', color: 'orange' },
LINK_ORDER: { text: '关联订单', color: 'purple' },
UNLINK_ORDER: { text: '取消关联', color: 'magenta' },
FIELD_CONFIRM: { text: '确认字段', color: 'green' },
DELETE: { text: '删除发票', color: 'red' },
}陷阱 3: TypeScript 无法检测
**场景**:字段名错误但 TypeScript 不报错
// ❌ TypeScript 不会报错(changedAt 在类型定义中存在)
dataIndex: 'changedAt' // 类型检查通过
render: (val: string) => new Date(val).toLocaleString()
// 运行时:val 为 undefined → Invalid Date
**正确做法**:
// ✅ 运行时测试 + 防御性编程
dataIndex: 'createdAt'
render: (val: string) => {
if (!val) return '-'
try {
return new Date(val).toLocaleString('zh-CN')
} catch {
return val
}
}陷阱 4: rowKey 使用可选字段
**场景**:rowKey 使用了可能为 undefined 的字段
**错误做法**:
// ❌ changedAt 可能为 undefined
rowKey={(record, index) => `${record.changedAt}-${index}`}
// 结果:undefined-0, undefined-1 → key 重复**正确做法**:
// ✅ 使用必填字段 id
rowKey={(record) => record.id}---
验证流程
1. 静态检查
# TypeScript 类型检查
npm run type-check
# ESLint 检查
npm run lint
2. 运行时测试
- [ ] 在开发环境中测试功能
- [ ] 检查是否显示 "Invalid Date"
- [ ] 检查是否显示 "undefined" 或空白
- [ ] 检查枚举值是否都有对应的映射
- [ ] 检查 rowKey 是否唯一
3. 对比验证
# 查看原始代码
git show HEAD~1:src/components/InvoiceHistoryTab.tsx
# 制作对比清单
| 字段 | 原始代码 | 重构后 | 状态 |
|------|---------|--------|------|
| 时间字段 | createdAt | changedAt | ❌ 错误 |
| 操作类型 | operationType | changeType | ❌ 错误 |
| 枚举映射 | 10 个 | 3 个 | ❌ 不完整 |
| rowKey | record.id | record.changedAt | ❌ 错误 |
---
防御性编程
1. 可选字段处理
// ✅ 检查字段是否存在
render: (val: string) => {
if (!val) return '-'
return val
}2. 日期格式化
// ✅ 捕获异常
render: (val: string) => {
if (!val) return '-'
try {
return new Date(val).toLocaleString('zh-CN', {
year: 'numeric',
month: '2-digit',
day: '2-digit',
hour: '2-digit',
minute: '2-digit',
second: '2-digit',
hour12: false,
})
} catch {
return val
}
}3. 枚举映射
// ✅ 提供默认值
render: (type: string) => {
const config = typeMap[type] || { text: type, color: 'default' }
return <Tag color={config.color}>{config.text}</Tag>
}---
规则溯源
> 📋 本回复遵循:`field-mapping-safety` - [章节]
Read more
name: field-mapping-safety description: 当重构涉及字段映射(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
// 原始代码有 10 个类型
typeMap: {
UPLOAD: { text: '上传发票', color: 'blue' },
OCR_START: { text: '开始OCR', color: 'cyan' },
OCR_SUCCESS: { text: 'OCR成功', color: 'green' },
OCR_FAILED: { text: 'OCR失败', color: 'red' },
OCR_RETRY: { text: '重试OCR', color: 'orange' },
MANUAL_EDIT: { text: '手动编辑', color: 'orange' },
LINK_ORDER: { text: '关联订单', color: 'purple' },
UNLINK_ORDER: { text: '取消关联', color: 'magenta' },
FIELD_CONFIRM: { text: '确认字段', color: 'green' },
DELETE: { text: '删除发票', color: 'red' },
}陷阱 3: TypeScript 无法检测
**场景**:字段名错误但 TypeScript 不报错
// ❌ TypeScript 不会报错(changedAt 在类型定义中存在) dataIndex: 'changedAt' // 类型检查通过 render: (val: string) => new Date(val).toLocaleString() // 运行时:val 为 undefined → Invalid Date
**正确做法**:
// ✅ 运行时测试 + 防御性编程
dataIndex: 'createdAt'
render: (val: string) => {
if (!val) return '-'
try {
return new Date(val).toLocaleString('zh-CN')
} catch {
return val
}
}陷阱 4: rowKey 使用可选字段
**场景**:rowKey 使用了可能为 undefined 的字段
**错误做法**:
// ❌ changedAt 可能为 undefined
rowKey={(record, index) => `${record.changedAt}-${index}`}
// 结果:undefined-0, undefined-1 → key 重复**正确做法**:
// ✅ 使用必填字段 id
rowKey={(record) => record.id}---
验证流程
1. 静态检查
# TypeScript 类型检查 npm run type-check # ESLint 检查 npm run lint
2. 运行时测试
- [ ] 在开发环境中测试功能
- [ ] 检查是否显示 "Invalid Date"
- [ ] 检查是否显示 "undefined" 或空白
- [ ] 检查枚举值是否都有对应的映射
- [ ] 检查 rowKey 是否唯一
3. 对比验证
# 查看原始代码 git show HEAD~1:src/components/InvoiceHistoryTab.tsx # 制作对比清单 | 字段 | 原始代码 | 重构后 | 状态 | |------|---------|--------|------| | 时间字段 | createdAt | changedAt | ❌ 错误 | | 操作类型 | operationType | changeType | ❌ 错误 | | 枚举映射 | 10 个 | 3 个 | ❌ 不完整 | | rowKey | record.id | record.changedAt | ❌ 错误 |
---
防御性编程
1. 可选字段处理
// ✅ 检查字段是否存在
render: (val: string) => {
if (!val) return '-'
return val
}2. 日期格式化
// ✅ 捕获异常
render: (val: string) => {
if (!val) return '-'
try {
return new Date(val).toLocaleString('zh-CN', {
year: 'numeric',
month: '2-digit',
day: '2-digit',
hour: '2-digit',
minute: '2-digit',
second: '2-digit',
hour12: false,
})
} catch {
return val
}
}3. 枚举映射
// ✅ 提供默认值
render: (type: string) => {
const config = typeMap[type] || { text: type, color: 'default' }
return <Tag color={config.color}>{config.text}</Tag>
}---
规则溯源
> 📋 本回复遵循:`field-mapping-safety` - [章节]
保留你熟悉的 CLI/IDE,让 Claude Code、Gemini CLI、Codex、Cursor、GitHub Copilot 开箱即用 按费力度从低到高,用最少操作获得最大帮助 不是提示词集合,而是一套可维护的 AI 协作配置系统。
Repo: doccker/cc-use-exp
Other skills on cc-use-exp.
- /api-design-safety
当设计或修改 REST API 响应结构、处理 API 返回值,或生成 Excel/CSV/PDF/对账文件等下游产物时触发。防止 API 设计缺陷导致的字段错位、类型歧义,以及生成产物时关键字段缺失但静默成功的问题。
Open skill - /api-proxy-safety
网关/代理/WAF/CDN 中间件的安全关键词匹配实现规范,防止纯子串匹配误判正常响应内容中的技术术语(如 Cloudflare、502、error)
Open skill - /async-task-pattern
当 API/任务可能执行超过 10 秒(批量数据处理、远程 API 批量调用、全表扫描、跨租户聚合)时触发。防止同步接口被网关 30s 超时切断、用户重复点击触发并发、状态缓存内存泄漏等问题。提供异步任务状态机标准模板。
Open skill - /bash-style
当用户操作 .sh、Dockerfile、Makefile、.yml、.yaml 文件,或在 Markdown 中编写 bash 代码块时触发。提供 Bash 编写规范。
Open skill - /code-quality-principles
当编写新模块、设计接口、重构代码或代码审查时触发。提供经典模块化六原则检查清单(大小适中/调用深度/扇入扇出/边界清晰/作用域内聚/可预测性),适用于 PR/Review/新模块设计场景。
Open skill - /external-system-debugging
涉及浏览器、编辑器、CDN/WAF、IM 平台、操作系统剪贴板、第三方 SaaS 等"外部黑盒系统"的代码编写或 bug 调试时触发。强制先抓真实环境数据再推理,避免连续 2 轮"凭代码推理"的修复 no-op。关键词:粘贴/复制异常、跨平台显示不一致、第三方 API 怪结果、CDN/WAF 拦截、本地复现失败、HTML→MD 转换丢属性。
Open skill

