跳到正文
cccskills
免费在 GitHub 公开

migrate-to-shoehorn

Replace TypeScript type assertions in tests with functions from @total-typescript/shoehorn. Use partial objects when only a few properties matter, or deliberately invalid data for error tests, then run a type check to verify the migration.

中文简介正在准备中。当前显示英语简介。

原文查看原文说明

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.

查看安装方法

适用场景

  • Replace as assertions in TypeScript tests
  • Build test objects with only the properties you need
  • Pass deliberately invalid data for error tests

包含的文件(2)

  • SKILL.md2.7 KB
  • agents/openai.yaml110 B

SKILL.md(原文)

安装前可以查看交给 AI 代理的指令内容。

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

FunctionUse 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

评价

还没有评价。欢迎分享你的使用感受。

评论

无需登录即可发表。欢迎分享使用感受、提问,或说明在哪些环境下无法运行。

还没有评论。来写第一条吧。

提交后会立即公开。请勿填写邮箱、电话等个人信息。URL 最多 2 个。

0 / 1000 字

此表单受 reCAPTCHA 保护,适用 Google 的隐私权政策和服务条款。

同一仓库的技能

ask-matt

免费

Choose which related skill to use and in what order for planning, building, debugging, or maintaining software. It explains routes through the available workflows and helps select the next step based on your situation and project size.

中文简介正在准备中。当前显示英语简介。

  • Choosing a workflow from idea to implementation
  • Finding the right starting point for bug investigation
  • Planning a build that spans multiple sessions
mattpocock/skills29.6万2026年10月13日 更新

chief-of-staff

免费有简介AI 评分 60分

在单次会话中协调承担不同任务的子智能体,推进长期目标。后台工作与用户对话同时进行,并改进共享规范、工作环境和后续任务所需的信息访问条件。

  • 协调长期目标中的任务分工
  • 后台推进工作并持续对话
  • 改进共享规范和工作环境
mattpocock/skills29.6万2026年10月13日 更新

claude-handoff

免费有简介AI 评分 90分

将进行中的对话整理为交接摘要,移除敏感信息,明确后续重点、参考资料和建议技能,再启动新的后台智能体,从当前工作目录继续处理任务。

  • 将后续工作交给新的智能体
  • 限定下一次会话的任务范围
  • 整理下一次会话所需的参考资料
mattpocock/skills29.6万2026年10月13日 更新

Review code changes from a chosen Git reference against two separate criteria: documented coding standards and the original requirements. Independent reviewers check each criterion, then present findings separately so convention problems and requirement gaps remain visible.

中文简介正在准备中。当前显示英语简介。

  • Reviewing changes on a branch or pull request
  • Checking changes since a chosen commit or tag
  • Checking compliance with documented coding standards
mattpocock/skills29.6万2026年10月13日 更新

Design modules that offer substantial behavior through a small interface, the rules callers must understand. Use shared design terms to simplify usage, contain complexity, choose where implementations can vary, and make behavior easier to test.

中文简介正在准备中。当前显示英语简介。

  • Simplifying a module's interface
  • Bringing scattered complexity into one module
  • Choosing where implementations can be swapped
mattpocock/skills29.6万2026年10月13日 更新

Investigate difficult bugs and performance slowdowns by building a repeatable test or script that detects the exact symptom. Reduce the failing case, compare possible causes, and verify the fix with checks that catch the bug if it returns.

中文简介正在准备中。当前显示英语简介。

  • Investigating an error that is hard to reproduce
  • Finding the cause of a performance slowdown
  • Testing an intermittent failure repeatedly
mattpocock/skills29.6万2026年10月13日 更新

查看 mattpocock 的全部技能

报告此技能的问题