Skip to content
Migrate to Shoehorn (Matt Pocock)

Migrate to Shoehorn (Matt Pocock) Skill

Matt Pocock's skill for replacing `as` type assertions in TypeScript tests with @total-typescript/shoehorn's fromPartial, fromAny and fromExact helpers.

GitHub Docs

Install

Install with the skills CLI

One command for Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, Windsurf and dozens of other agents. Needs Node.js; the skill is fetched straight from mattpocock/skills.

$ npx skills add mattpocock/skills --skill migrate-to-shoehorn

Run it in a terminal. The CLI finds the agents installed on your machine, asks which ones to add the skill to, and whether to install it into the folder you ran it from or for all your projects.

Other ways to install

Copy the whole skill folder — SKILL.md and any scripts or references beside it — into ~/.claude/skills/migrate-to-shoehorn/, where Claude Code picks it up in every project. Only git is needed.

tmp=$(mktemp -d) && \
  git clone --depth 1 --branch main https://github.com/mattpocock/skills.git "$tmp" && \
  mkdir -p ~/.claude/skills && \
  cp -R "$tmp"/skills/misc/migrate-to-shoehorn ~/.claude/skills/migrate-to-shoehorn

No scripts or references next to it? Saving the SKILL.md alone as ~/.claude/skills/migrate-to-shoehorn/SKILL.md works too.

Using another agent? Its personal skills folder
Codex
~/.agents/skills/
Cursor
~/.cursor/skills/
GitHub Copilot
~/.copilot/skills/
Gemini CLI
~/.gemini/skills/
Windsurf
~/.codeium/windsurf/skills/
OpenCode
~/.config/opencode/skills/

About

  • Rewrites `as Type` test data to fromPartial()
  • Rewrites `as unknown as Type` to fromAny() for intentionally wrong inputs
  • Explains when to use fromExact()
  • Finds assertions across *.test.ts and *.spec.ts files
  • Restricts shoehorn to test code
  • Verifies the migration with a type check

Migrate to Shoehorn is a skill by Matt Pocock, author of Total TypeScript and of the @total-typescript/shoehorn library it migrates to. It teaches an agent to clean up TypeScript test files that fake their inputs with as Type or as unknown as Type.

The problem it targets is common in test suites: a function takes a large object (a request, a context, a config) but a test only cares about one or two properties, so the test either fakes every field or casts its way past the compiler. Shoehorn's helpers keep partial test data type-safe instead. The skill maps each pattern to its replacement: as Type becomes fromPartial(), a deliberately wrong as unknown as Type becomes fromAny() (which keeps autocomplete), and fromExact() forces a full object when that is what the test needs.

The workflow asks which test files and objects are causing trouble, installs the package, finds assertions in *.test.ts and *.spec.ts files with a grep, rewrites them, adds the imports and runs the type checker. It is explicit that shoehorn belongs in test code only, never production code.

For TypeScript developers using Claude Code, Codex, Cursor or another skills-compatible agent on a Vitest or Jest test suite. MIT licensed.

SKILL.md

The instructions your agent loads, as published by Matt Pocock.

SKILL.md
name
migrate-to-shoehorn
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.

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?
  1. 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
Install

Skill: Codebase Design

by Matt Pocock

New

Matt Pocock's skill that gives coding agents a shared vocabulary for designing deep modules: interfaces, seams, adapters, depth, leverage and locality, plus rules for testable design.

Matt Pocock's skill that wires Husky, lint-staged and Prettier into a JavaScript or TypeScript repo, so every commit is formatted, type-checked and tested before it lands.

Skill: Ponytail

by Dietrich Gebert

New

A coding-agent skill that works like a lazy senior developer: the smallest complete change that solves the task, no speculative code, and a short reply naming what was skipped.

Matt Pocock's /improve-codebase-architecture command: finds shallow modules worth deepening, renders them as a visual HTML report with before/after diagrams, then grills you through the one you pick.

Browse all skills →