migrate-to-shoehorn

Migrates TypeScript test files from `as` assertions to @total-typescript/shoehorn partial mocks.

Updated May 9, 2024
One-click install
npx skills add https://github.com/AceCodePt/dotfiles --skill migrate-to-shoehorn-acecodept
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: migrate-to-shoehorn
Source: https://github.com/AceCodePt/dotfiles/tree/main/.config/opencode/skills/migrate-to-shoehorn
Command: npx skills add https://github.com/AceCodePt/dotfiles --skill migrate-to-shoehorn-acecodept

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires @total-typescript/shoehorn.

What problem does it solve? TypeScript tests often rely on as type assertions or double-assertions (as unknown as Type) to fake large objects, which is brittle, verbose, and hides type errors. This Skill replaces those assertions with type-safe partial mocks from @total-typescript/shoehorn. ## Core Features & Use Cases - Partial object mocking: Replace as Type with fromPartial() so tests only specify the properties they actually use. - Intentionally wrong data: Replace as unknown as Type with fromAny() for error-path testing while keeping autocomplete. - Guided migration workflow: Find affected test files with grep, swap assertions, add imports, and verify with a type check. - Use Case: A test needs a Request object with 20+ properties but only uses body.id. Instead of faking every property, pass fromPartial({ body: { id: "123" } }). ## Quick Start Migrate my test files that use as type assertions to @total-typescript/shoehorn and run the type checker to verify.

Frequently Asked Questions about migrate-to-shoehorn

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I replace `as` type assertions in TypeScript tests?▼

Replace `as Type` with `fromPartial()` from @total-typescript/shoehorn, which accepts partial data while keeping TypeScript satisfied. For intentionally wrong data, replace `as unknown as Type` with `fromAny()`.

What is @total-typescript/shoehorn used for?▼

Shoehorn lets you pass partial data in tests while keeping TypeScript happy, replacing `as` assertions with type-safe alternatives. It provides fromPartial(), fromAny(), and fromExact() for different mocking needs.

When should I use fromPartial vs fromAny vs fromExact?▼

Use fromPartial() to pass partial data that still type-checks, fromAny() to pass intentionally wrong data while keeping autocomplete, and fromExact() to force a full object that you can swap with fromPartial later.

Can I use shoehorn in production code?▼

No. Shoehorn is for test code only and should never be used in production code, since it bypasses full type safety to allow partial or intentionally incorrect data.

How do I find test files that need shoehorn migration?▼

Search for assertions with grep: `grep -r " as [A-Z]" --include="*.test.ts" --include="*.spec.ts"`. Then replace each `as Type` with fromPartial() and each `as unknown as Type` with fromAny(), and run a type check to verify.