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가 스킬을 읽고 지침을 따릅니다.
바로 붙여넣을 수 있는 메시지
Claude Code, Codex, Cursor용입니다. 프로젝트 폴더에서 실행하면 스킬이 설치됩니다.
SKILL.md를 다운로드해 에이전트의 스킬 폴더에 넣으세요.
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
Gather requirements - ask user:
- What test files have
asassertions causing problems? - Are they dealing with large objects where only some properties matter?
- Do they need to pass intentionally wrong data for error testing?
- What test files have
Install and migrate:
- Install:
npm i @total-typescript/shoehorn - Find test files with
asassertions:grep -r " as [A-Z]" --include="*.test.ts" --include="*.spec.ts" - Replace
as TypewithfromPartial() - Replace
as unknown as TypewithfromAny() - Add imports from
@total-typescript/shoehorn - Run type check to verify
- Install:
자주 묻는 질문
운영 코드에서도 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.
댓글
- …
이 저장소의 다른 스킬
ask-matt
310k에이전트가 아이디어에서 배포된 코드까지 이어지는 코딩 스킬 모음의 안내자가 되어, 상황에 맞는 스킬을 찾아 주도록 돕습니다.
code-review
310k마지막 기준점 이후 바뀐 내용을 저장소의 코딩 표준과 원래 명세에 나란히 비교해, 병합 전에 검토하도록 돕습니다.
domain-modeling
310k팀이 쓰는 용어를 담은 공유 프로젝트 용어집을 만들고, 중요한 설계 결정을 기록해 코드가 같은 단어를 쓰도록 돕습니다.
implement-spec
310k완성된 명세와 그 티켓을 작동하는 코드로 바꾸고, 티켓을 순서대로 처리한 뒤 하나의 브랜치에 모아 줍니다.