All skills
mattpocock avatar

/migrate-to-shoehorn

@62f43a1 official
by Matt Pocockmattpocock/skills274k stars
22,991

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.

Use this Skill: https://skilld.dev/gh/mattpocock/skills/migrate-to-shoehorn

This session only. Nothing lands on disk.

SKILL.md

≈47 tokens always: the name and description. ≈645 when used: this file. ≈28 more on demand in 1 file.

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

Source: SKILL.md on GitHub

1 warning16d5 checks · Risk SAFE
  • Gen Agent Trust Hub16d

    The skill is safe to use. It provides instructions and patterns for migrating TypeScript test files from 'as' type assertions to the @total-typescript/shoehorn library. It uses standard development tools like npm and grep to perform these tasks and involves installing a legitimate package from the author's official brand.

  • Socket16d

    No alerts

  • Snyk16d

    Risk: LOW · No issues

  • Runlayer7mo

    1/1 file flagged

  • ZeroLeaks5mo

    Score: 93/100 · 2 sections analyzed

Signed by skilld at 62f43a1. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 2 days ago.

Activeupdated 5 months ago

README badge

README badge for mattpocock/skills/migrate-to-shoehorn

Migrates test files from `as` type assertions to @total-typescript/shoehorn, replacing unsafe casts with `fromPartial()` for partial test data and `fromAny()` for intentionally wrong types. Targets test-only TypeScript codebases where large objects need minimal properties faked.

Generated from the current SKILL.md.

Does this work in production code?
No. Shoehorn is designed for test code only and should never be used in production.
What's the difference between fromPartial() and fromAny()?
fromPartial() lets you pass partial data that still type-checks. fromAny() lets you pass intentionally wrong data (useful for error testing) while keeping autocomplete.
Does this replace all uses of `as` in tests?
It targets `as Type` and `as unknown as Type` patterns in test files. The skill focuses on cases where you're mocking large objects with only a few needed properties or testing with intentionally wrong types.

Generated from the current SKILL.md. These answers refresh after source changes.