migrate-to-shoehorn

仓库创建 2026年2月2日最近提交 4 天前SkillHot 收录 21 天前
▸ 精选理由

对大型 TS 项目有用,可减少不安全的测试断言。

这个 Skill 做什么

把测试中的 as 断言迁移为 @total-typescript/shoehorn 的类型安全写法。

把测试里乱用的 as 类型断言替换为 @total-typescript/shoehorn 提供的类型安全写法,让测试能传入部分数据同时保留 TypeScript 校验。只针对测试代码,绝不用于生产代码,能避免双重 as(as unknown as Type)等不安全写法。适合要减小类型断言、提升测试类型可靠性或需要构造部分测试数据时用。

▸ 展开 SKILL.md 英文原文

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.

开发编程TypeScript测试迁移shoehorn通用
458
Stars
41
Forks
34
仓库内 Skill
+10
7 日增星
安装 / 使用
给你的 Agent 一句话(通用)
帮我安装这个 skill:https://raw.githubusercontent.com/mxyhi/ok-skills/main/migrate-to-shoehorn/SKILL.md
或 curl 直取 SKILL.md
curl -fsSL "https://raw.githubusercontent.com/mxyhi/ok-skills/main/migrate-to-shoehorn/SKILL.md"
SKILL.MD 节选查看完整文件 ↗
# 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

```bash
npm i @total-typescript/shoehorn
```

## Migration patterns

### Large objects with few needed properties

Before:

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

it("gets user by id", (
via SKILL·HOT · 数据来自 GitHub 公开信息 · 原文版权归作者所有