migrate-to-shoehorn

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.

npx skills add https://github.com/mattpocock/skills --skill migrate-to-shoehorn

Migrate to Shoehorn

Why shoehorn?

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:

  • Trained not to use it
  • Must manually specify target type
  • Double-as (as unknown as Type) for intentionally wrong data

Install

npm i @total-typescript/shoehorn

Migration patterns

Large objects with few needed properties

Before:

type Request = {
  body: { id: string };
  headers: Record<string, string>;
  cookies: Record<string, string>;
  // ...20 more properties
};

it("gets user by id", () => {
  // Only care about body.id but must fake entire 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 TypefromPartial()

Before:

getUser({ body: { id: "123" } } as Request);

After:

import { fromPartial } from "@total-typescript/shoehorn";

getUser(fromPartial({ body: { id: "123" } }));

as unknown as TypefromAny()

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 } }));

When to use each

FunctionUse case
fromPartial()Pass partial data that still type-checks
fromAny()Pass intentionally wrong data (keeps autocomplete)
fromExact()Force full object (swap with fromPartial later)

Workflow

  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"
    • Replace as Type with fromPartial()
    • Replace as unknown as Type with fromAny()
    • Add imports from @total-typescript/shoehorn
    • Run type check to verify

Thêm skills từ mattpocock

improve-codebase-architecture
mattpocock
Tìm cơ hội đào sâu trong một mã nguồn, dựa trên ngôn ngữ miền trong CONTEXT.md và các quyết định trong docs/adr/. Sử dụng khi người dùng muốn cải thiện kiến trúc, tìm cơ hội tái cấu trúc, hợp nhất các mô-đun kết nối chặt chẽ, hoặc làm cho mã nguồn dễ kiểm thử và dễ điều hướng bởi AI hơn.
developmentcode-reviewapi
tdd
mattpocock
Phát triển hướng theo kiểm thử với vòng lặp đỏ-xanh-tái cấu trúc. Sử dụng khi người dùng muốn xây dựng tính năng hoặc sửa lỗi bằng TDD, đề cập đến "đỏ-xanh-tái cấu trúc", muốn kiểm thử tích hợp, hoặc yêu cầu phát triển kiểm thử trước.
developmenttesting
handoff
mattpocock
Nén cuộc hội thoại hiện tại thành một tài liệu bàn giao để một tác nhân khác tiếp nhận.
communicationproject-managementdocument
prototype
mattpocock
Xây dựng một bản mẫu dùng một lần để phát triển thiết kế trước khi cam kết thực hiện. Định tuyến giữa hai nhánh — một ứng dụng terminal có thể chạy được để kiểm tra trạng thái/logic nghiệp vụ, hoặc nhiều biến thể giao diện khác nhau có thể chuyển đổi từ một tuyến đường. Sử dụng khi người dùng muốn tạo bản mẫu, kiểm tra tính hợp lý của mô hình dữ liệu hoặc máy trạng thái, phác thảo giao diện, khám phá các lựa chọn thiết kế, hoặc nói "tạo bản mẫu này", "cho tôi thử nghiệm", "thử một vài thiết kế".
developmentdesigncreative
triage
mattpocock
Phân loại vấn đề thông qua máy trạng thái được điều khiển bởi các vai trò phân loại. Sử dụng khi người dùng muốn tạo vấn đề, phân loại vấn đề, xem xét lỗi mới hoặc yêu cầu tính năng, chuẩn bị vấn đề cho tác nhân AFK, hoặc quản lý quy trình làm việc vấn đề.
developmentproject-managementcommunication
obsidian-vault
mattpocock
Tìm kiếm, tạo và quản lý ghi chú trong kho Obsidian với wikilinks và ghi chú chỉ mục. Sử dụng khi người dùng muốn tìm, tạo hoặc sắp xếp ghi chú trong Obsidian.
productivitydocument
edit-article
mattpocock
Chỉnh sửa và cải thiện bài viết bằng cách tái cấu trúc các phần, nâng cao độ rõ ràng và thắt chặt văn phong. Sử dụng khi người dùng muốn chỉnh sửa, sửa đổi hoặc cải thiện bản nháp bài viết.
documentcreative
writing-great-skills
mattpocock
Tài liệu tham khảo để viết và chỉnh sửa skill tốt — từ vựng và nguyên tắc giúp skill có tính dự đoán được.
documentdevelopment