agentleFS
Boom-VittBoom-Vitt/skills-thai/skills/misc/migrate-to-shoehorn/SKILL.md

migrate-to-shoehorn

Skill5 starsChanged 4 months agoMITView on GitHub

ย้าย test file จาก type assertion แบบ `as` ไปใช้ @total-typescript/shoehorn ใช้เมื่อ user พูดถึง shoehorn อยากเลิกใช้ `as` ใน test หรือต้องการส่ง test data แบบ partial

  • Installs packages

94 other projects use a version of this, 93 of them edited.

Adopted by

Most recently taken up by

Used with

Projects with it also use batch-grill-me, decision-mapping and 1 more.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • boyingliu01Skill

    batch-grill-me

    A relentless interview that asks every frontier question at once, round by round. Thin alias of `grilling` (#540) — upstream mattpocock/skills absorbed this protocol into grilling; XP-Gate keeps this name as the sprint-flow Phase 2 entry point so orchestration docs stay stable.

    Also in 6 projects that use this

  • FabienDehopreSkill

    decision-mapping

    Turn a loose idea into a sequenced map of investigation tickets, then drive them to resolution one at a time.

    Also in 4 projects that use this

  • getnaoSkill

    chief-of-staff

    Also in 11 projects that use this

The file

We split this skill into the rules it gives an agent

1 rule. 0 are common, 0 are distinctive, and 1 is very specific to this project.

  • 0

    Common

    Most of the 85 edited versions we read keep these.

  • 0

    Distinctive

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    test file ไหนบ้างที่มี assertion แบบ as แล้วสร้างปัญหา?

    line 108

“Common” is measured: kept by at least 6 in 10 of the 85 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

ย้ายไปใช้ Shoehorn

ทำไมต้อง shoehorn?

shoehorn ช่วยให้ส่ง data แบบ partial ใน test ได้โดยที่ TypeScript ยังแฮปปี้ มันมาแทน assertion แบบ as ด้วยทางเลือกที่ type-safe

ใช้ใน test code เท่านั้น ห้ามใช้ shoehorn ใน production code เด็ดขาด

ปัญหาของ as ใน test:

  • โมเดลถูก train มาไม่ให้ใช้มัน
  • ต้องระบุ type ปลายทางเองทุกครั้ง
  • ต้องใช้ double-as (as unknown as Type) เวลาตั้งใจส่ง data ผิด type

ติดตั้ง

npm i @total-typescript/shoehorn

รูปแบบการ migrate

object ใหญ่แต่ใช้จริงแค่ไม่กี่ property

ก่อน:

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

หลัง:

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

it("gets user by id", () => {
  getUser(
    fromPartial({
      body: { id: "123" },
    }),
  );
});

as Type → fromPartial()

ก่อน:

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

หลัง:

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

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

as unknown as Type → fromAny()

ก่อน:

getUser({ body: { id: 123 } } as unknown as Request); // wrong type on purpose

หลัง:

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

getUser(fromAny({ body: { id: 123 } }));

เลือกใช้ตัวไหนเมื่อไหร่

ฟังก์ชันกรณีใช้งาน
fromPartial()ส่ง data แบบ partial ที่ยังผ่าน type check
fromAny()ส่ง data ที่ตั้งใจให้ผิด type (ยังได้ autocomplete)
fromExact()บังคับ object แบบเต็ม (ค่อยสลับเป็น fromPartial ทีหลัง)

ขั้นตอนการทำงาน

  1. เก็บ requirement - ถาม user:
    • test file ไหนบ้างที่มี assertion แบบ as แล้วสร้างปัญหา?
    • กำลังเจอ object ใหญ่ ๆ ที่สนใจจริงแค่บาง property หรือเปล่า?
    • ต้องส่ง data ที่ตั้งใจให้ผิด type สำหรับ test เคส error ไหม?
  2. ติดตั้งแล้ว migrate:
    • ติดตั้ง: npm i @total-typescript/shoehorn
    • หา test file ที่มี assertion แบบ as: grep -r " as [A-Z]" --include="*.test.ts" --include="*.spec.ts"
    • แทนที่ as Type ด้วย fromPartial()
    • แทนที่ as unknown as Type ด้วย fromAny()
    • เพิ่ม import จาก @total-typescript/shoehorn
    • รัน type check เพื่อยืนยันว่าผ่าน

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.