Agent Skills › poteto/noodle › ts-best-practices

ts-best-practices

GitHub

提供 TypeScript 类型安全最佳实践,涵盖区分联合、类型守卫、穷尽检查等规范。用于编写或审查 TS 代码时确保类型严格与安全。

.agents/skills/ts-best-practices/SKILL.md poteto/noodle

Trigger Scenarios

编写 TypeScript 代码 审查 TypeScript 代码的类型安全性 询问类型安全、类型收窄或区分联合相关概念

Install

npx skills add poteto/noodle --skill ts-best-practices -g -y
More Options

Non-standard path

npx skills add https://github.com/poteto/noodle/tree/main/.agents/skills/ts-best-practices -g -y

Use without installing

npx skills use poteto/noodle@ts-best-practices

指定 Agent (Claude Code)

npx skills add poteto/noodle --skill ts-best-practices -a claude-code -g -y

安装 repo 全部 skill

npx skills add poteto/noodle --all -g -y

预览 repo 内 skill

npx skills add poteto/noodle --list

SKILL.md

Frontmatter
{
    "name": "ts-best-practices",
    "description": "TypeScript type safety guidelines for writing maximally type-safe code. Apply these patterns when writing or reviewing any TypeScript: discriminated unions, type narrowing, type guards, exhaustiveness checks, avoiding `as` casts, preferring `unknown` over `any`, and making impossible states unrepresentable. Use this skill whenever writing TypeScript code, reviewing TypeScript for type safety issues, or when the user mentions type safety, type narrowing, discriminated unions, or asks to make types stricter\/more explicit."
}

Type Safety

This project's TypeScript policy. Apply when writing or reviewing TypeScript.

Rule Summary
No as casts Every as is a potential runtime crash. Validate at boundaries, then cast only if earned. Prefer Zod/Valibot over manual validation.
unknown over any any disables type checking for everything it touches. External data is always unknown.
Discriminated unions Model variants with a shared literal discriminant. No optional-field bags.
Narrowing hierarchy Prefer: discriminated union switch > in operator > typeof/instanceof > type guard > as
Type guards Must actually verify the claim. Name them isX or hasX. Prefer discriminant narrowing when possible.
Exhaustiveness checks Always add default: never arm to switches over discriminated unions. Use an absurd() helper to reduce boilerplate.
satisfies over as When verifying a value matches a type without widening, use satisfies to preserve literal types.
Impossible states If a bug requires asking "can this combination happen?" the type is too loose. Tighten it.

Read references/patterns.md for code examples of each rule.

Version History

  • 82d2921 Current 2026-11-19 21:09

Same Skill Collection

.agents/skills/adversarial-review/SKILL.md
.agents/skills/ast-grep/SKILL.md
.agents/skills/brain/SKILL.md
.agents/skills/codex/SKILL.md
.agents/skills/commit/SKILL.md
.agents/skills/debugging/SKILL.md
.agents/skills/execute/SKILL.md
.agents/skills/find-skills/SKILL.md
.agents/skills/frontend-design/SKILL.md
.agents/skills/go-best-practices/SKILL.md
.agents/skills/interaction-design/SKILL.md
.agents/skills/make-interfaces-feel-better/SKILL.md
.agents/skills/meditate/SKILL.md
.agents/skills/noodle/SKILL.md
.agents/skills/oops/SKILL.md
.agents/skills/plan/SKILL.md
.agents/skills/quality/SKILL.md
.agents/skills/react-best-practices/SKILL.md
.agents/skills/refine/SKILL.md
.agents/skills/reflect/SKILL.md
.agents/skills/review/SKILL.md
.agents/skills/ruminate/SKILL.md
.agents/skills/schedule/SKILL.md
.agents/skills/skill-creator/SKILL.md
.agents/skills/testing/SKILL.md
.agents/skills/todo/SKILL.md
.agents/skills/unslop/SKILL.md
.agents/skills/worktree/SKILL.md
examples/minimal/.agents/skills/execute/SKILL.md
examples/minimal/.agents/skills/schedule/SKILL.md
examples/multi-skill/.agents/skills/execute/SKILL.md
examples/multi-skill/.agents/skills/schedule/SKILL.md
skills/skill-creator/SKILL.md
examples/multi-skill/.agents/skills/deploy/SKILL.md
examples/multi-skill/.agents/skills/test/SKILL.md

Metadata

Files
0
Version
82d2921
Hash
db7236ec
Indexed
2026-11-19 21:09

홈 - 위키
Copyright © 2011-2026 iteam. Current version is 2.156.0. UTC+08:00, 2026-11-19 22:21
浙ICP备14020137号-1