Migrate tests to shoehorn
Replaces as and as unknown as casts in TypeScript tests with fromPartial and fromAny from @total-typescript/shoehorn, adds the imports and runs the type check. Use when tests fake whole objects or cast partial test data to satisfy the compiler.
migrate-to-shoehorn- Author
- Matt Pocock
- Source
- mattpocock/skills/skills/misc/migrate-to-shoehorn @ abeeaf9
- License
- MIT · Copyright (c) 2026 Matt Pocock
About this skill
What it does
The skill moves TypeScript tests off as type assertions and onto @total-typescript/shoehorn, a library for passing partial data in tests. Three functions replace the casts:
fromPartial()instead ofas Type, for a large object where the test needs a few fields: a request with twenty properties when the code under test reads onlybody.id.fromAny()instead ofas unknown as Type, for data that is wrong on purpose; autocomplete keeps working.fromExact(), which demands the full object and can be swapped forfromPartial()later.
The agent first asks which test files have troublesome assertions, whether the objects are large with few relevant fields, and whether you pass deliberately wrong data to test errors. Then it installs the package, finds candidates with grep -r " as [A-Z]" over *.test.ts and *.spec.ts, replaces the casts, adds the imports and runs the type check.
The skill is SKILL.md alone, with before-and-after examples; agents/openai.yaml holds the name and short description for Codex.
When to use it, and when not
Use it in a TypeScript project whose tests are full of as and as unknown as, or where every test builds a whole object just to satisfy the compiler.
Not for production code: the skill says shoehorn belongs in tests only. The install line is npm i without -D, so say if you want it under devDependencies or use another package manager. The search covers only .test.ts and .spec.ts; tests named differently or written in .tsx need a wider pattern.
How to run it
The install command below puts the whole folder in place. The agent picks the skill up by its description when shoehorn or casts in tests come up; to call it yourself:
- Claude Code:
/migrate-to-shoehorn, or ask for the skill by name. - Codex:
$migrate-to-shoehorn. - Cursor: type
/in the Agent chat and pickmigrate-to-shoehorn.
Example: /migrate-to-shoehorn Replace the as casts in src/api, install shoehorn as a dev dependency and run tsc at the end.
How it differs from similar skills
Nothing in our catalog does this migration. Unit test writer writes new tests for existing code and fakes only the boundaries, but says nothing about typing test data. Code simplification removes type assertions that repeat an inferred type, in any code and without a replacement. This skill is narrow: one library, one kind of change, test files only.
Install
Run one command — it saves SKILL.md and the files it uses into your agent's skills folder. Claude Code and Codex pick up a new skill without a restart; if it does not show up, restart the agent.
curl -fsSL --create-dirs -o ~/.claude/skills/migrate-to-shoehorn/SKILL.md https://anymodel.org/en/skills/matt-pocock/migrate-to-shoehorn/SKILL.md -o ~/.claude/skills/migrate-to-shoehorn/LICENSE https://anymodel.org/en/skills/matt-pocock/migrate-to-shoehorn/LICENSE -o ~/.claude/skills/migrate-to-shoehorn/agents/openai.yaml https://anymodel.org/en/skills/matt-pocock/migrate-to-shoehorn/agents/openai.yaml
curl -fsSL --create-dirs -o ~/.agents/skills/migrate-to-shoehorn/SKILL.md https://anymodel.org/en/skills/matt-pocock/migrate-to-shoehorn/SKILL.md -o ~/.agents/skills/migrate-to-shoehorn/LICENSE https://anymodel.org/en/skills/matt-pocock/migrate-to-shoehorn/LICENSE -o ~/.agents/skills/migrate-to-shoehorn/agents/openai.yaml https://anymodel.org/en/skills/matt-pocock/migrate-to-shoehorn/agents/openai.yaml
foreach ($f in 'SKILL.md','LICENSE','agents/openai.yaml') { $p = Join-Path "$HOME\.claude\skills\migrate-to-shoehorn" $f; New-Item -ItemType Directory -Force (Split-Path $p) | Out-Null; Invoke-WebRequest "https://anymodel.org/en/skills/matt-pocock/migrate-to-shoehorn/$f" -UseBasicParsing -OutFile $p }foreach ($f in 'SKILL.md','LICENSE','agents/openai.yaml') { $p = Join-Path "$HOME\.agents\skills\migrate-to-shoehorn" $f; New-Item -ItemType Directory -Force (Split-Path $p) | Out-Null; Invoke-WebRequest "https://anymodel.org/en/skills/matt-pocock/migrate-to-shoehorn/$f" -UseBasicParsing -OutFile $p }Any other agent: save the file into its skills folder, or give it the link to the file: https://anymodel.org/en/skills/matt-pocock/migrate-to-shoehorn/SKILL.md
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
Gather requirements - ask user:
- What test files have
asassertions causing problems? - Are they dealing with large objects where only some properties matter?
- Do they need to pass intentionally wrong data for error testing?
- What test files have
Install and migrate:
- Install:
npm i @total-typescript/shoehorn - Find test files with
asassertions:grep -r " as [A-Z]" --include="*.test.ts" --include="*.spec.ts" - Replace
as TypewithfromPartial() - Replace
as unknown as TypewithfromAny() - Add imports from
@total-typescript/shoehorn - Run type check to verify
- Install:
Connect through AnyModel API
This skill runs on whatever model your agent uses. Point Claude Code, Codex or Cursor at AnyModel to run it on Claude, GPT, Gemini and more with one key — pay per token, no subscription.
AnyModel