migrate-to-shoehorn

Replace unsafe TypeScript as assertions with @total-typescript/shoehorn functions in tests.

88|9|Updated Jul 16, 2020
One-click install
npx skills add https://github.com/docs-plus/docs.plus --skill migrate-to-shoehorn-docs-plus
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: migrate-to-shoehorn
Source: https://github.com/docs-plus/docs.plus/tree/main/.agents/skills/migrate-to-shoehorn
Command: npx skills add https://github.com/docs-plus/docs.plus --skill migrate-to-shoehorn-docs-plus

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill addresses the common pain point of using unsafe manual as type assertions in TypeScript test files, which require developers to manually specify target types, fake all properties of large objects even when only a few are needed, and use double as unknown as Type casts for intentionally incorrect test data, all of which reduce test maintainability and type safety.

Core Features & Use Cases

  • Safe Partial Data Passing: Replaces as Type assertions with the fromPartial() function to pass only the required properties of large objects in tests, eliminating the need to fake unused fields.
  • Intentional Invalid Data Support: Replaces double as unknown as Type casts with the fromAny() function to pass intentionally incorrect test data for error scenario testing while retaining autocomplete support.
  • Use Case Example: When testing a function that accepts a 20+ property request object but only requires the body.id field, this Skill removes the need to define all 20 unused properties in test mocks.

Quick Start

Use the migrate-to-shoehorn skill to replace all as type assertions in your TypeScript test files with the appropriate @total-typescript/shoehorn functions for your use case.

Frequently Asked Questions about migrate-to-shoehorn

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

FAQPage Schema
How do I pass partial data to TypeScript functions in tests without faking all object properties?

You can pass partial test data by replacing manual `as Type` assertions with the type-safe `fromPartial()` function, which eliminates the need to fake unused properties for large object parameters in TypeScript tests.

What is the best way to pass intentionally incorrect data in TypeScript tests for error scenarios?

The best way to pass intentionally incorrect test data is using the `fromAny()` function, replacing double `as unknown as Type` casts to inject invalid data while retaining autocomplete support for error scenario testing.

Why do I need to use double type casts like as unknown as Type in my test files?

Double type casts like `as unknown as Type` are used to bypass TypeScript compiler errors when passing intentionally incorrect data for error scenario testing, but they can be replaced with safer `fromAny()` functions for better maintainability.

How do I migrate unsafe type assertions in TypeScript test suites to type-safe alternatives?

To migrate unsafe type assertions in TypeScript test suites, replace manual `as Type` casts with `@total-typescript/shoehorn` functions like `fromPartial()` for partial data and `fromAny()` for invalid data to restore type safety and remove boilerplate.

Can I use shoehorn functions with existing TypeScript test suites that rely heavily on type assertions?

Yes, you can use shoehorn functions with existing TypeScript test suites by replacing unsafe manual `as Type` assertions with `fromPartial()` or `fromAny()` to refactor large object mocks and double type casts into type-safe test code.