Provides TypeScript best practices for error handling patterns and project conventions. Use when handling errors, designing Result types, or implementing retry logic. Triggers: "错误处理", "Result类型", "自定义Error", "重试", "最佳实践".
Provides TypeScript best practices for error handling patterns and project conventions. Use when handling errors, designing Result types, or implementing retry logic. Triggers: "错误处理", "Result类型", "自定义Error", "重试", "最佳实践".
/plugin marketplace add 15195999826/LomoMarketplace/plugin install typescript-style@LomoMarketplaceThis skill inherits all available tools. When active, it can use any tool Claude has access to.
类型相关内容参见 using-typescript-types skill。
| 场景 | 项目约定 |
|---|---|
| 预期错误 | Result 类型 |
| 意外错误 | 自定义 Error 类 |
| 网络请求 | 指数退避重试 |
| 空值默认 | ??(不用 ||) |
对于可预期的失败,使用 Result 类型替代 throw:
type Result<T, E = Error> =
| { success: true; data: T }
| { success: false; error: E }
async function parseConfig(path: string): Promise<Result<Config, string>> {
try {
const content = await fs.readFile(path, 'utf-8')
return { success: true, data: JSON.parse(content) }
} catch {
return { success: false, error: 'Failed to parse config' }
}
}
// 调用方
const result = await parseConfig('./config.json')
if (result.success) console.log(result.data)
else console.error(result.error)
class ValidationError extends Error {
constructor(message: string, public field: string, public code: string) {
super(message)
this.name = 'ValidationError'
}
}
class NotFoundError extends Error {
constructor(resource: string, id: string) {
super(`${resource} with id ${id} not found`)
this.name = 'NotFoundError'
}
}
async function fetchWithRetry<T>(fn: () => Promise<T>, maxRetries = 3): Promise<T> {
for (let i = 0; i <= maxRetries; i++) {
try {
return await fn()
} catch (error) {
if (i === maxRetries) throw error
await sleep(1000 * Math.pow(2, i)) // 1s, 2s, 4s...
}
}
throw new Error('Unreachable')
}
This skill should be used when the user asks to "create an agent", "add an agent", "write a subagent", "agent frontmatter", "when to use description", "agent examples", "agent tools", "agent colors", "autonomous agent", or needs guidance on agent structure, system prompts, triggering conditions, or agent development best practices for Claude Code plugins.
This skill should be used when the user asks to "create a slash command", "add a command", "write a custom command", "define command arguments", "use command frontmatter", "organize commands", "create command with file references", "interactive command", "use AskUserQuestion in command", or needs guidance on slash command structure, YAML frontmatter fields, dynamic arguments, bash execution in commands, user interaction patterns, or command development best practices for Claude Code.
This skill should be used when the user asks to "create a hook", "add a PreToolUse/PostToolUse/Stop hook", "validate tool use", "implement prompt-based hooks", "use ${CLAUDE_PLUGIN_ROOT}", "set up event-driven automation", "block dangerous commands", or mentions hook events (PreToolUse, PostToolUse, Stop, SubagentStop, SessionStart, SessionEnd, UserPromptSubmit, PreCompact, Notification). Provides comprehensive guidance for creating and implementing Claude Code plugin hooks with focus on advanced prompt-based hooks API.