AGENT SKILL

Shoehorn 测试断言迁移

migrate-to-shoehorn

将测试文件中的 `as` 类型断言迁移为 @total-typescript/shoehorn。当用户提到 shoehorn、希望在测试中替换 `as` 或需要部分测试数据时使用。

适用职业测试工程师
License 许可
MIT
最近更新
2026-11-14
Stars
★ 5
Forks
0

01 前言 Front Matter

name
migrate-to-shoehorn
license
MIT
metadata
{ "author": "Matt Pocock", "version": "1.0" }
description
Migrate test files from `as` type assertions to @total-typescript/shoehorn. Use when user mentions shoehorn, wants to replace `as` in tests, or needs partial test data.

02 资源文件 1

03 SKILL.md 正文

Migrate to Shoehorn

Why shoehorn?

shoehorn lets you pass partial data in tests while keeping TypeScript happy. It replaces as assertions with type-safe alternatives.

Test code only. Never use shoehorn in production code.

Problems with as in tests:

  • Trained not to use it
  • Must manually specify target type
  • Double-as (as unknown as Type) for intentionally wrong data

Install

npm i @total-typescript/shoehorn

Migration patterns

Large objects with few needed properties

Before:

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
  });
});

After:

import { fromPartial } from "@total-typescript/shoehorn";

it("gets user by id", () => {
  getUser(
    fromPartial({
      body: { id: "123" },
    }),
  );
});

as Type → fromPartial()

Before:

getUser({ body: { id: "123" } } as Request);

After:

import { fromPartial } from "@total-typescript/shoehorn";

getUser(fromPartial({ body: { id: "123" } }));

as unknown as Type → fromAny()

Before:

getUser({ body: { id: 123 } } as unknown as Request); // wrong type on purpose

After:

import { fromAny } from "@total-typescript/shoehorn";

getUser(fromAny({ body: { id: 123 } }));

When to use each

Function Use case
fromPartial() Pass partial data that still type-checks
fromAny() Pass intentionally wrong data (keeps autocomplete)
fromExact() Force full object (swap with fromPartial later)

Workflow

  1. Gather requirements - ask user:

    • What test files have as assertions causing problems?
    • Are they dealing with large objects where only some properties matter?
    • Do they need to pass intentionally wrong data for error testing?
  2. Install and migrate:

    • [ ] Install: npm i @total-typescript/shoehorn
    • [ ] Find test files with as assertions: grep -r " as [A-Z]" --include="*.test.ts" --include="*.spec.ts"
    • [ ] Replace as Type with fromPartial()
    • [ ] Replace as unknown as Type with fromAny()
    • [ ] Add imports from @total-typescript/shoehorn
    • [ ] Run type check to verify

04 同仓库更多 Skills

fderuiter
fderuiter/QRCraftly-web

会话交接至后台智能体

claude-handoff

将当前会话交接给一个全新的后台智能体,由其立即接手继续工作。

软件开发工程师会话上下文交接
★ 5
fderuiter
fderuiter/QRCraftly-web

QRCraftly PR 合并管理

steward

如何将 QRCraftly 的拉取请求(PR)推进至合并。适用于创建 PR、处理其上的 CI 或评审事件、更新分支,或决定是否合并。

软件开发工程师代码仓库协作管理
★ 5
fderuiter
fderuiter/QRCraftly-web

QRCraftly 应用运行测试

run-qrcraftly

构建、运行并驱动 QRCraftly Web 应用(Vike + React on Vite)。适用于以下场景:启动开发服务器或生产预览、对页面截图、在生成器或二维码检查器中逐步点击操作、下载生成的二维码、确认 UI 变更在真实应用中生效、直接调用 src/packages 中的函数,或在本容器中运行单元测试与 Playwright 端到端(e2e)测试。

软件开发工程师二维码生成与定制
★ 5
fderuiter
fderuiter/QRCraftly-web

素材成文写作

writing-shape

写作,发挥:将原始素材逐段塑造成一篇文章。

内容创作者创意写作与内容编排
★ 5
fderuiter
fderuiter/QRCraftly-web

写作片段素材挖掘

writing-fragments

写作,探索阶段:挖掘原始素材片段,暂不组织结构。

内容创作者创意写作与内容编排
★ 5
fderuiter
fderuiter/QRCraftly-web

智能体文档编写

writing-for-agents

为智能体编写文档。适用于创建或编辑技能(skill),或修改 AGENTS.md 或 CLAUDE.md。

技术文档工程师技术文档编写
★ 5