跳转到内容
关系图谱

migrate-to-shoehorn(Matt)

229 字 1 分钟

属性 8
repo
mattpocock_skills
skill
migrate-to-shoehorn
source
mattpocock_skills/skills/misc/migrate-to-shoehorn/SKILL.md
invoke
model
phase
build
cost
low
status
frozen
local
same
一句话

把测试文件里的 as 断言迁到 @total-typescript/shoehorn:fromPartial() 传部分数据、fromAny() 传故意错的数据。

何时用 ​

  • 适合:测试里 as 泛滥、大对象只用少数字段、要 as unknown as 造错数据测错误路径。
  • 不适合:生产代码(shoehorn 只给测试用,这是硬规则)。

怎么用 ​

text
把测试里的 as 断言迁到 shoehorn
  1. 先问需求:哪些测试文件的 as 有问题、是不是大对象只用几字段、要不要故意错数据。
  2. npm i @total-typescript/shoehorn,grep -r " as [A-Z]" --include="*.test.ts" --include="*.spec.ts" 找目标。
  3. as Type → fromPartial(),as unknown as Type → fromAny(),补 import。
  4. 跑 typecheck 验证。

产出 ​

  • 迁移后的测试文件 + devDependency。

要点与坑 ​

  • 三函数按用途选:fromPartial() 部分数据仍过类型检查、fromAny() 错数据保留自动补全、fromExact() 先全量后可换 fromPartial。
  • 在 misc 桶,frozen。

关联 ​