Migrate to Shoehorn

Migrate to Shoehorn

Migrates TypeScript test files from unsafe as assertions to the shoehorn library's fromPartial and fromAny helpers for partial test data.

Skill files2 files

agents/

SKILL.md119 lines
1
---
2
name: migrate-to-shoehorn
3
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.
4
---
5
6
# Migrate to Shoehorn
7
8
## Why shoehorn?
9
10
`shoehorn` lets you pass partial data in tests while keeping TypeScript happy. It replaces `as` assertions with type-safe alternatives.
11
12
**Test code only.** Never use shoehorn in production code.
13
14
Problems with `as` in tests:
15
16
- Trained not to use it
17
- Must manually specify target type
18
- Double-as (`as unknown as Type`) for intentionally wrong data
19
20
## Install
21
22
```bash
23
npm i @total-typescript/shoehorn
24
```
25
26
## Migration patterns
27
28
### Large objects with few needed properties
29
30
Before:
31
32
```ts
33
type Request = {
34
body: { id: string };
35
headers: Record<string, string>;
36
cookies: Record<string, string>;
37
// ...20 more properties
38
};
39
40
it("gets user by id", () => {
41
// Only care about body.id but must fake entire Request
42
getUser({
43
body: { id: "123" },
44
headers: {},
45
cookies: {},
46
// ...fake all 20 properties
47
});
48
});
49
```
50
51
After:
52
53
```ts
54
import { fromPartial } from "@total-typescript/shoehorn";
55
56
it("gets user by id", () => {
57
getUser(
58
fromPartial({
59
body: { id: "123" },
60
}),
61
);
62
});
63
```
64
65
### `as Type` → `fromPartial()`
66
67
Before:
68
69
```ts
70
getUser({ body: { id: "123" } } as Request);
71
```
72
73
After:
74
75
```ts
76
import { fromPartial } from "@total-typescript/shoehorn";
77
78
getUser(fromPartial({ body: { id: "123" } }));
79
```
80
81
### `as unknown as Type` → `fromAny()`
82
83
Before:
84
85
```ts
86
getUser({ body: { id: 123 } } as unknown as Request); // wrong type on purpose
87
```
88
89
After:
90
91
```ts
92
import { fromAny } from "@total-typescript/shoehorn";
93
94
getUser(fromAny({ body: { id: 123 } }));
95
```
96
97
## When to use each
98
99
| Function | Use case |
100
| --------------- | -------------------------------------------------- |
101
| `fromPartial()` | Pass partial data that still type-checks |
102
| `fromAny()` | Pass intentionally wrong data (keeps autocomplete) |
103
| `fromExact()` | Force full object (swap with fromPartial later) |
104
105
## Workflow
106
107
1. **Gather requirements** - ask user:
108
- What test files have `as` assertions causing problems?
109
- Are they dealing with large objects where only some properties matter?
110
- Do they need to pass intentionally wrong data for error testing?
111
112
2. **Install and migrate**:
113
- [ ] Install: `npm i @total-typescript/shoehorn`
114
- [ ] Find test files with `as` assertions: `grep -r " as [A-Z]" --include="*.test.ts" --include="*.spec.ts"`
115
- [ ] Replace `as Type` with `fromPartial()`
116
- [ ] Replace `as unknown as Type` with `fromAny()`
117
- [ ] Add imports from `@total-typescript/shoehorn`
118
- [ ] Run type check to verify
119

© Matt Pocock · MIT · source · posted by @OpenSourceBuffGuy on promptparty.com

@OpenSourceBuffGuy

I find openly licensed prompts and post them here.

0 followers · 6,373 prompts

More by @OpenSourceBuffGuy

See all
Website Clone Architect prompt image

Website Clone Architect

Reverse-engineers a website section by section, writes component specs, and hands them to parallel builder agents in git worktrees to rebuild it.

agent-skill, orchestrator, parallel-agents, multi-agent, plan-then-execute, web-development, frontend, codebase-analysis, scaffolding, css, html, nextjs, typescript, git, mcp, claude-code, for-developers, for-designers, long-form, advanced, technical-spec, task-decomposition, structured-output, design-systems, ui-ux, tool-use, checklist, report, vibe-coding

Italian Terrace Cafe Candid Portrait prompt image

Italian Terrace Cafe Candid Portrait

Generates a photorealistic candid shot of a woman in a white corset dress laughing at a sunny hotel terrace cafe, written as detailed JSON.

image-prompt, json-prompt, structured-output, photorealistic, portrait, woman, candid, fashion, cottagecore, natural-light, golden-hour, bokeh, summer, travel, cityscape, mountains, medium-shot, vibrant-colors, for-photographers, nano-banana, fashion-shoot, luxury

Night Street Photo With Leashed Cat prompt image

Night Street Photo With Leashed Cat

Generates a flash-lit night street photo of a blonde woman in a retro track jacket walking a hissing tabby cat on a leash.

image-prompt, json-prompt, nano-banana, structured-output, portrait, woman, animals, pet-portrait, night-scene, street-photography, candid, editorial, fashion, dramatic-lighting, photorealistic, vertical-format, medium-shot, graffiti, for-photographers, for-content-creators

1 view

Reviews

Loading reviews…

Discussion

Loading comments…