一键导入
typescript
TypeScript error handling via union returns, strictness policy, runtime validation with Zod, monorepo contracts, and domain types vs DTOs.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
TypeScript error handling via union returns, strictness policy, runtime validation with Zod, monorepo contracts, and domain types vs DTOs.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Enforce and guide the Mikado Method when a developer is refactoring, restructuring, or dealing with legacy code. Use this skill whenever the user mentions refactoring, technical debt, legacy code, code restructuring, dependency untangling, or "breaking everything" when making changes. Also trigger when the user wants to make a large change safely, asks how to split a big refactoring task, wants to work on main branch without a long-lived feature branch, or asks how to incrementally improve a codebase. The skill enforces the full Mikado loop: goal → naive attempt → map prerequisites → revert → implement leaves → commit → repeat.
Evaluate TypeScript/JavaScript code against Dave Thomas's OO principles and the Tell Don't Ask rule. Trigger when: class has only static methods; class has a single public method + constructor; code uses GoF pattern names (Decorator/Factory/Strategy/Builder/Command/Observer); class is invalid until setters are called; data class with only constructor + properties; external code reads getters to make decisions (Tell Don't Ask); user asks "is this a code smell?", "should this be a class or a function?", or "why does my code feel procedural?".
Detect code smells and apply refactoring techniques to improve clarity, testability, and maintainability.
Guide users through TDD and TCRDD (Test && Commit || Revert + Test Driven Development). Use this skill whenever a user mentions TDD, test-driven development, writing tests before code, red-green-refactor cycles, or unit testing workflows. Also trigger when a user asks about TCRDD, TCR, "test commit revert", "git gamble", or wants a strict TDD workflow with automatic commits and reverts. Trigger when the user asks to implement a feature, fix a bug, or write a class/function and mentions tests, TDD, or "test first". If the user shares code and asks for a review with any testing angle, consult this skill.
Master testing strategy — philosophy, approach, architecture decisions, test quality audit, and BDD review practices.
Design patterns for TypeScript—Factory, Strategy, Builder, Decorator, Singleton, Mixin, and more with problem-oriented and GoF triggers.
| name | typescript |
| description | TypeScript error handling via union returns, strictness policy, runtime validation with Zod, monorepo contracts, and domain types vs DTOs. |
| triggers | ["TypeScript error handling","Zod validation","strict mode","runtime validation","domain vs DTO","typescript best practices","handle errors without throwing","validate API response","type safety","typescript strictness","ts-expect-error","monorepo types","api contract"] |
→ Design patterns (Strategy, Factory, Builder, Decorator, Mixin…) → design-patterns/ sub-skill
→ Type system (unknown/any, narrowing, discriminated unions, mapped types…) → type-system/ sub-skill
→ SOLID principles (SRP, OCP, LSP, ISP, DIP) → solid/ sub-skill
| Strategy | Caller forced to handle? | Composability |
|---|---|---|
| Return `T | null` | Yes (null check) |
| Throw exception | No — easy to miss | High |
| Return exception `T | ErrorA | ErrorB` |
| Option/Either type | Via .flatMap chain | High (needs library) |
Return exceptions (preferred for expected failures):
class BadRequestError extends Error {
readonly status = 400 as const;
}
class UnauthorizedError extends Error {
readonly status = 401 as const;
}
class NotFoundError extends Error {
readonly status = 404 as const;
}
function resolveUser(
token: string,
id: string,
): User | BadRequestError | UnauthorizedError | NotFoundError {
if (!id.trim()) return new BadRequestError("Missing user ID");
if (!isValidJwt(token)) return new UnauthorizedError("Invalid token");
const user = userStore.get(id);
if (!user) return new NotFoundError(`User ${id} not found`);
return user;
}
const result = resolveUser(authHeader, userId);
if (result instanceof BadRequestError) res.status(400).send(result.message);
else if (result instanceof UnauthorizedError)
res.status(401).send(result.message);
else if (result instanceof NotFoundError) res.status(404).send(result.message);
else res.status(200).json(result);
Enable "strict": true globally and enforce in CI. Prefer @ts-expect-error over @ts-ignore. Track and reduce any usage via linting.
Keep API/DTO types separate. Map external responses into domain objects at boundaries.
type UserDTO = { user_id: string; display_name: string; created_at: string };
type User = { id: string; name: string; createdAt: Date };
function toDomain(dto: UserDTO): User {
return { id: dto.user_id, name: dto.display_name, createdAt: new Date(dto.created_at) };
}
Validate external inputs (API bodies, env vars, queues) at boundaries with Zod.
const UserSchema = z.object({ id: z.string(), name: z.string() });
const user = UserSchema.parse(req.body);
Publish domain contracts as @org/contracts. Use TypeScript project references to enforce boundaries.
Track and reduce any usage, null inconsistency, and duplicate definitions via @typescript-eslint/no-explicit-any.
Types are documentation. If they confuse humans, they’re failing.
references/user-example.md.references/zod-example.md.