This commit is contained in:
Matt Pocock
2026-02-04 14:06:26 +00:00
parent 64b2f99245
commit c90b246c92
+9 -1
View File
@@ -9,6 +9,8 @@ description: Migrate test files from `as` type assertions to @total-typescript/s
`shoehorn` lets you pass partial data in tests while keeping TypeScript happy. It replaces `as` assertions with type-safe alternatives. `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: Problems with `as` in tests:
- Trained not to use it - Trained not to use it
@@ -102,7 +104,13 @@ getUser(fromAny({ body: { id: 123 } }));
## Workflow ## Workflow
- [ ] Install package 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"` - [ ] Find test files with `as` assertions: `grep -r " as [A-Z]" --include="*.test.ts" --include="*.spec.ts"`
- [ ] Replace `as Type` with `fromPartial()` - [ ] Replace `as Type` with `fromPartial()`
- [ ] Replace `as unknown as Type` with `fromAny()` - [ ] Replace `as unknown as Type` with `fromAny()`