본문으로 건너뛰기
Skillpedia
테스트310k · #121

migrate-to-shoehorn

하는 일

타입 단축 표현을 쓰는 테스트 코드를 shoehorn 라이브러리의 더 안전한 도우미 함수로 바꾸도록 안내합니다. 일부 데이터만 가진 TypeScript 테스트를 작성하는 개발자를 위한 스킬입니다.

사용하는 경우

  • ✓테스트 파일에서 as 타입 단언으로 가짜 데이터를 만들고 있을 때.
  • ✓모든 속성을 적지 않고 일부 테스트 데이터만 필요할 때.
  • ✓as unknown as 캐스팅을 테스트에서 바꾸고 싶을 때.

스킬 링크

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

복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.

사용 방법

가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.

바로 붙여넣을 수 있는 메시지

Use this skill to help me: https://github.com/mattpocock/skills/blob/main/skills/misc/migrate-to-shoehorn/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
AI가 이런 스킬을 알아서 찾아 쓰길 원하시나요?무료 Skillpedia MCP를 설치하세요. 한 줄이면 작업마다 스킬 15,000+개 중에서 검색합니다.1분 만에 설치 →

AI에게 요청하는 예시

“테스트 파일의 as 캐스팅을 shoehorn으로 바꿔서 테스트가 타입 안전하게 유지되도록 해 주세요.”

매주 새 스킬 5개. 읽는 데 1분.

작동 방식

에이전트는 라이브러리를 설치하고, 각 테스트 패턴을 맞는 도우미로 바꿉니다. 일부 데이터에는 fromPartial을, 일부러 타입과 맞지 않는 데이터에는 fromAny를 씁니다. 테스트 코드만 변경합니다.

기술 내용 (원본 SKILL.md)

작성자의 영어 원문을 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
자주 묻는 질문

운영 코드에서도 shoehorn을 쓸 수 있나요?

아닙니다. 이 스킬은 테스트 코드 전용이라고 설명합니다.

fromPartial은 무엇을 하나요?

테스트에 필요한 필드만 넘길 수 있게 해 주며, TypeScript는 여전히 타입을 검사합니다.

fromAny는 무엇에 쓰나요?

테스트가 의도적으로 타입과 맞지 않는 데이터를 넘기는 경우를 위한 것입니다.

상세 정보

작성자의 원본 설명

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

인기도

GitHub 스타
310k
순위
#121
라이선스
MIT
업데이트
2026. 11. 1.

이 스킬이 유용한가요?

0

로그인 투표하려면 로그인하세요.

댓글

  • …

이 저장소의 다른 스킬

비슷한 스킬