Not loaded · from mattpocock-skills
Migrates TypeScript test files from `as` type assertions to `@total-typescript/shoehorn` for type-safe partial data. Activated when user mentions shoehorn or replacing `as` in tests.
Claude Code won't load this skill
It ships in mattpocock-skills at skills/, but Claude Code only loads skills/<name>/SKILL.md and folders listed under skills in plugin.json. Installing the plugin doesn't add it.
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 多个属性
};
it("gets user by id", () => {
// 只关心 body.id,但必须伪造整个 Request
getUser({
body: { id: "123" },
headers: {},
cookies: {},
// ...伪造全部 20 个属性
});
});
之后:
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); // 故意用错误的类型
之后:
import { fromAny } from "@total-typescript/shoehorn";
getUser(fromAny({ body: { id: 123 } }));
| 函数 | 使用场景 |
|---|---|
fromPartial() | 传入仍能通过类型检查的部分数据 |
fromAny() | 传入故意错误的数据(保留自动补全) |
fromExact() | 强制要求完整对象(之后可换成 fromPartial) |
收集需求 —— 询问用户:
as 断言造成了问题?安装并迁移:
npm i @total-typescript/shoehornas 断言的测试文件:grep -r " as [A-Z]" --include="*.test.ts" --include="*.spec.ts"as Type 替换为 fromPartial()as unknown as Type 替换为 fromAny()@total-typescript/shoehorn 的导入What SKILL.md sets; muted values are Claude Code's defaults
Generated from the plugin's indexed repository (wenwuzhidao/mattpocock-skills-zh) — no native marketplace selected
npx claudepluginhub p/wenwuzhidao-mattpocock-skills35 skills in this plugin
/ask-matt询问哪个技能或流程适合你当前的情况。它是本仓库中各技能的路由器。/claude-handoff把当前对话移交给一个全新的后台 agent,它会立即接手工作。/codebase-design用于设计深模块的共享词汇。当用户想设计或改进一个模块的接口、寻找深化机会、决定接缝放在何处、让代码更可测试或更易于 AI 导航,或当另一个技能需要深模块词汇时使用。/code-review审查自某个固定基点(commit、分支、tag 或 merge-base)以来的改动,沿两条轴进行——标准(代码是否遵循本仓库记录的编码规范?)和规格(代码是否符合源头工单/规格的要求?)。两项审查在并行子 agent 中运行,并把结果并排报告。当用户想审查一个分支、一个 PR、进行中的改动,或要求「审查自 X 以来」时使用。/diagnosing-bugs针对疑难 bug 和性能回归的诊断循环。当用户说「诊断」/「调试这个」,或报告某个东西坏了/抛异常/失败/变慢时使用。/domain-modeling构建并打磨项目的领域模型。当用户想要确定领域术语或通用语言、记录一项架构决策,或当其他技能需要维护领域模型时使用。Other plugins' skills for the same job