Langsung ke konten
Skillpedia
Testing310k Β· #121

migrate-to-shoehorn

Fungsinya

Skill ini mengubah kode tes yang memakai pintasan tipe menjadi fungsi bantu shoehorn yang lebih aman. Skill ini ditujukan bagi pengembang yang menulis tes TypeScript dengan data uji parsial.

Kapan dipakai

  • βœ“Saat file tes Anda memakai asersi as type untuk memalsukan data.
  • βœ“Ketika Anda memerlukan data uji parsial tanpa menuliskan setiap properti.
  • βœ“Ketika Anda ingin mengganti cast as unknown as di dalam tes.

Link skill

https://github.com/mattpocock/skills/blob/main/skills/misc/migrate-to-shoehorn/SKILL.md

Salin lalu tempelkan ke AI Anda (Claude, ChatGPT, atau Cursor) dan minta AI mengikuti instruksinya.

Cara pakai

Cara paling mudah: salin pesan ini dan tempelkan ke AI Anda. AI akan membaca skill dan mengikuti instruksinya.

Pesan siap tempel

Gunakan skill ini untuk membantu saya: https://github.com/mattpocock/skills/blob/main/skills/misc/migrate-to-shoehorn/SKILL.md Baca file SKILL.md di link tersebut dan ikuti instruksinya untuk tugas saya.
Mau AI Anda menemukan skill seperti ini sendiri?Pasang MCP Skillpedia gratis: cukup satu baris, dan AI mencari di antara 15.000+ skill sebelum tiap tugas.Pasang dalam 1 menit β†’

Contoh permintaan ke AI

β€œGanti cast as di file tes kami dengan shoehorn agar tes tetap aman secara tipe.”

5 skill baru setiap minggu. 1 menit baca.

Cara kerjanya

Agent memasang pustaka dan menulis ulang setiap pola tes menjadi fungsi bantu yang sesuai, misalnya fromPartial untuk data parsial atau fromAny untuk data yang sengaja tidak cocok. Skill hanya mengubah kode tes.

Konten teknis (SKILL.md asli)

Teks asli dari pembuat, dalam bahasa Inggris, langsung dari GitHub.

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 Type β†’ fromPartial()

Before:

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

After:

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

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

as unknown as Type β†’ fromAny()

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

Function Use 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
Pertanyaan umum

Bisakah saya memakai shoehorn di kode produksi?

Tidak. Skill menyatakan ini hanya untuk kode tes.

Apa yang dilakukan fromPartial?

Fungsi ini memungkinkan Anda hanya memberikan field yang dibutuhkan tes, sementara TypeScript tetap memeriksa tipenya.

Untuk apa fromAny?

Untuk kasus ketika tes sengaja memberikan data yang tidak sesuai dengan tipe.

Detail

Deskripsi asli dari pembuat

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.

repo: mattpocock/skills

Popularitas

Bintang GitHub
310k
Peringkat
#121
Lisensi
MIT
Diperbarui
1/11/2026

Apakah skill ini berguna?

0

Masuk untuk memberi suara.

Komentar

  • …

Skill lain dari repositori ini

Skill serupa