AGENT SKILL
migrate-to-shoehorn
把测试文件从 `as` 类型断言迁移到 @total-typescript/shoehorn。当用户提到 shoehorn、想替换测试中的 `as`,或需要部分测试数据时使用。
- License 许可
- MIT
- 最近更新
- 2026-10-19
- Stars
- ★ 0
- Forks
- 0
01 前言 Front Matter
- name
- migrate-to-shoehorn
- description
- 把测试文件从 `as` 类型断言迁移到 @total-typescript/shoehorn。当用户提到 shoehorn、想替换测试中的 `as`,或需要部分测试数据时使用。
- commit_version
- 62f43a18177be6ec82da242e59ffbc490a4c22ea
02 资源文件 1
- 参考文档agents/openai.yaml104 B
03 SKILL.md 正文
迁移到 Shoehorn
为什么用 shoehorn?
shoehorn 让你在测试中传入部分数据的同时让 TypeScript 满意。它用类型安全的替代品替换 as 断言。
仅限测试代码。 永远不要在生产代码中使用 shoehorn。
测试中使用 as 的问题:
- 我们被训练成不要用它
- 必须手动指定目标类型
- 故意传错数据时需要双重断言(
as unknown as Type)
安装
npm i @total-typescript/shoehorn
迁移模式
只需要少数属性的大对象
之前:
type Request = {
body: { id: string };
headers: Record<string, string>;
cookies: Record<string, string>;
// ...20 more properties
};
it("gets user by id", () => {
// Only care about body.id but must fake entire Request
getUser({
body: { id: "123" },
headers: {},
cookies: {},
// ...fake all 20 properties
});
});
之后:
import { fromPartial } from "@total-typescript/shoehorn";
it("gets user by id", () => {
getUser(
fromPartial({
body: { id: "123" },
}),
);
});
as Type → fromPartial()
之前:
getUser({ body: { id: "123" } } as Request);
之后:
import { fromPartial } from "@total-typescript/shoehorn";
getUser(fromPartial({ body: { id: "123" } }));
as unknown as Type → fromAny()
之前:
getUser({ body: { id: 123 } } as unknown as Request); // wrong type on purpose
之后:
import { fromAny } from "@total-typescript/shoehorn";
getUser(fromAny({ body: { id: 123 } }));
什么时候用哪个
| 函数 | 使用场景 |
|---|---|
fromPartial() |
传入仍能通过类型检查的部分数据 |
fromAny() |
传入故意错误的数据(保留自动补全) |
fromExact() |
强制完整对象(之后可与 fromPartial 互换) |
工作流程
-
收集需求——问用户:
- 哪些测试文件有造成问题的
as断言? - 他们是否在处理只有部分属性重要的大对象?
- 他们是否需要为错误测试传入故意错误的数据?
- 哪些测试文件有造成问题的
-
安装并迁移:
- [ ] 安装:
npm i @total-typescript/shoehorn - [ ] 找出带
as断言的测试文件:grep -r " as [A-Z]" --include="*.test.ts" --include="*.spec.ts" - [ ] 把
as Type替换为fromPartial() - [ ] 把
as unknown as Type替换为fromAny() - [ ] 添加来自
@total-typescript/shoehorn的 import - [ ] 运行类型检查验证
- [ ] 安装:
04 同仓库更多 Skills
skills-link
管理 muscaestar/skills 仓库的 skill 安装。当用户想安装/卸载某个 skill、查看已装清单、把 skill 装到全局或某个项目、或问"这个 skill 装了没有"时使用。也用于向用户解释三层结构与全局/项目双范围安装策略。
★ 0
writing-shape
写作之 exploit:把原始素材塑形成一篇文章,逐段进行。
★ 0
writing-fragments
写作之 explore:开采原始碎片,还没有结构。
★ 0
writing-for-agents
为 agents 编写文档。在创建或编辑技能,或修改 AGENTS.md 或 CLAUDE.md 时使用。
★ 0
writing-beats
写作之 exploit;把原始素材组装成一段由节拍(beat)构成的旅程,在每个节拍倚赖某个术语之前先把它落地。
★ 0
wizard
生成一个交互式 bash 向导,引导人类完成只有他们才能执行的步骤。当需要配置基础设施、设置凭据或 CI secret、摸索不熟悉的第三方仪表盘,或执行一次性的迁移或切换时使用。不要为 agent 自己能执行的步骤调用本技能。
★ 0