migrate-to-shoehorn
将测试文件中的 `as` 类型断言迁移到 @total-typescript/shoehorn。当用户提到 shoehorn、想要在测试中替换 `as`、或需要部分测试数据时使用。
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
القائمة
将测试文件中的 `as` 类型断言迁移到 @total-typescript/shoehorn。当用户提到 shoehorn、想要在测试中替换 `as`、或需要部分测试数据时使用。
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
استنادا إلى تصنيف SOC المهني
Manage git submodules for the learning-open-code mono-repo. Use when the user wants to: (1) Add a new git submodule — auto-detect or specify the category (open-ai-skills/open-sdd/open-ai-agent/open-ai-desktop/open-knowledge/open-productivity/open-java/open-trading/open-data), record the tracking branch in .gitmodules, clone the repo, and update README.md index. (2) Sync all existing submodules to their configured branches (git fetch + checkout branch + pull). (3) Update the root README.md with an up-to-date index of all synced projects grouped by category. (4) Initialize submodules after git clone — when open-*/ directories are empty or git submodule status returns nothing, guide through the full SOP (git submodule update --init --recursive [--remote]). Trigger keywords: submodule, git submodule, 子模块, add submodule, sync submodule, update submodule, submodule branch, README index, 更新索引, clone, init, 初始化子模块, submodule init, 拉取子模块.
对开源项目进行穷尽式教学文档生成——从宏观架构到微观实现的五层分级讲解,使用 Goal Loop 算法自主驱动完整代码覆盖。所有具体教学内容生成必须激活 `.agents/skills/teach/SKILL.md`。触发条件:用户要求"完整学习某个项目"、"生成项目架构文档"、"从入口到落地讲清楚每个功能"、"代码考古"、"源码分析"、或指定一个项目目录/仓库要求全面教学。
使用并行子 agent 为模块生成多个截然不同的接口设计。当用户想要设计 API、探索接口选项、比较模块形态,或提到 "设计两次" 时使用。
交互式 QA 会话,用户以对话方式报告 bug 或问题,agent 将其录入 GitHub Issue。在后台探索代码库以获取上下文和领域语言。当用户想要报告 bug、做 QA、以对话方式录入 issue,或提及 "QA session" 时使用。
通过用户访谈创建包含微小提交的详细重构计划,并将其录入 GitHub Issue。当用户想要规划重构、创建重构 RFC,或将重构分解为安全的渐进步骤时使用。
从当前对话中提取 DDD 风格的通用语言词汇表,标记歧义并提出规范术语。保存到 UBIQUITOUS_LANGUAGE.md。当用户想要定义领域术语、构建词汇表、固化术语、创建通用语言,或提到 "领域模型" 或 "DDD" 时使用。
| name | migrate-to-shoehorn |
| description | 将测试文件中的 `as` 类型断言迁移到 @total-typescript/shoehorn。当用户提到 shoehorn、想要在测试中替换 `as`、或需要部分测试数据时使用。 |
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("根据 id 获取用户", () => {
// 只关心 body.id 但必须伪造整个 Request
getUser({
body: { id: "123" },
headers: {},
cookies: {},
// ...伪造全部 20 多个属性
});
});
迁移后:
import { fromPartial } from "@total-typescript/shoehorn";
it("根据 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 的导入