用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/autohandai/community-skills --skill typescript-refactoring-patterns命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
Build, convert, validate, and install Autohand extensions, including Pi adaptations.
Run Weizhena's Deep Research workflow in Autohand Code for outline generation, deep web investigation, structured evidence capture, and final research reports.
Use Aaronontheweb dotnet-skills for Claude Code-oriented .NET maintenance, refactoring, and agent workflows.
基于 SOC 职业分类
正在显示 SKILL.md
| name | typescript-refactoring-patterns |
| description | Expert TypeScript refactoring patterns for cleaner, type-safe code |
| license | MIT |
| compatibility | typescript 5.0+ |
| allowed-tools | read_file write_file apply_patch search_with_context |
as castsas const for immutable literal typesextends constraints over anyWhen you see multiple boolean flags, refactor to discriminated union:
// Before
interface User {
isAdmin: boolean;
isGuest: boolean;
permissions?: string[];
}
// After
type User =
| { role: 'admin'; permissions: string[] }
| { role: 'guest' }
| { role: 'member'; permissions: string[] };
When you see switch statements on type, use the strategy pattern:
// Before
function process(item: Item) {
switch (item.type) {
case 'a': return processA(item);
case 'b': return processB(item);
}
}
// After
const processors: Record<ItemType, (item: Item) => Result> = {
a: processA,
b: processB,
};
const process = (item: Item) => processors[item.type](item);
When narrowing types, create reusable type guards:
function isNonNullable<T>(value: T): value is NonNullable<T> {
return value !== null && value !== undefined;
}
// Usage
const items = array.filter(isNonNullable);
Prevent primitive obsession with branded types:
type UserId = string & { readonly brand: unique symbol };
type Email = string & { readonly brand: unique symbol };
function createUserId(id: string): UserId {
if (!isValidUuid(id)) throw new Error('Invalid user ID');
return id as UserId;
}
Watch for these patterns and refactor:
any types (replace with unknown + type guards)! (add proper checks)as (use type guards)?.?.?. (restructure data)strict: true in tsconfigsatisfies for type checking without wideningreadonly arrays and objectsunknown for external data, validate at boundaries