migrate-to-shoehorn
Convert `as` type assertions in test files to @total-typescript/shoehorn helpers. Use when the user mentions shoehorn, wants to remove `as` from tests, or needs to pass partial data to a typed function under test.
- License 许可
- Apache-2.0
- 最近更新
- 2026-11-06
- Stars
- ★ 7
- Forks
- 0
01 前言 Front Matter
- name
- migrate-to-shoehorn
- description
- Convert `as` type assertions in test files to @total-typescript/shoehorn helpers. Use when the user mentions shoehorn, wants to remove `as` from tests, or needs to pass partial data to a typed function under test.
03 SKILL.md 正文
Migrate to shoehorn
Why shoehorn
shoehorn (published as @total-typescript/shoehorn) lets a test hand a function partial data without the compiler complaining. It swaps casts for helpers that stay type-checked, so the test still fails when the real shape drifts.
Tests only. Keep shoehorn out of production code.
What as costs you in tests:
- It defeats the compiler you are trying to lean on
- You restate the target type by hand at every call site
- Deliberately wrong fixtures need the double cast
as unknown as Type
Install
npm i @total-typescript/shoehorn
Migration patterns
A large object where the test needs a couple of fields
Before:
type Request = {
body: { id: string };
headers: Record<string, string>;
cookies: Record<string, string>;
// ...20 more properties
};
it("gets user by id", () => {
// The test only reads body.id, yet has to fabricate a whole 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 becomes fromPartial()
Before:
getUser({ body: { id: "123" } } as Request);
After:
import { fromPartial } from "@total-typescript/shoehorn";
getUser(fromPartial({ body: { id: "123" } }));
as unknown as Type becomes 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 } }));
Which helper to reach for
| Function | Use case |
|---|---|
fromPartial() |
Supply partial data that still type-checks |
fromAny() |
Supply deliberately wrong data (autocomplete stays) |
fromExact() |
Require the full object (swap for fromPartial later) |
Workflow
-
Scope the change — ask the user:
- Which test files carry the problematic
asassertions? - Are these large objects where the test reads only a few fields?
- Do any tests intentionally pass malformed data to exercise error paths?
- Which test files carry the problematic
-
Install, then migrate:
- [ ] Install:
npm i @total-typescript/shoehorn - [ ] Locate the casts:
grep -r " as [A-Z]" --include="*.test.ts" --include="*.spec.ts" - [ ] Turn
as TypeintofromPartial() - [ ] Turn
as unknown as TypeintofromAny() - [ ] Import the helpers from
@total-typescript/shoehorn - [ ] Run the type checker to confirm the tests still compile
- [ ] Install:
04 同仓库更多 Skills
writing-great-skills
Reference for writing and editing skills well — the vocabulary and principles that make a skill predictable.
technical-writing
House style for technical writing — the voice, sentence craft, formatting, and user-facing-copy rules that make docs and product text clear, direct, and consistent. Use when writing or editing a README, docs, a spec, release notes, a changelog, help text, or any error/CLI/UI copy a person reads; when reviewing a diff that touches prose or messages; or when a project needs a writing standard. Reference-heavy mechanics live in REFERENCE.md.
teach
Teach the user a new skill or concept, within this workspace.
handoff
Compact the current conversation into a handoff document for another agent to pick up.
grilling
Interrogate the user's plan or design one decision at a time until you both share the same understanding. Use when the user wants to pressure-test an idea before building it, or reaches for any 'grill' trigger phrase.
grill-me
A relentless, one-decision-at-a-time interview that sharpens a plan or design.