typescript-best-practices
TypeScript guidance. Use when writing or reviewing .ts or .tsx code.
- License 许可
- MIT
- 所属仓库
- syanga/astack
- 最近更新
- 2026-11-14
- Stars
- ★ 0
- Forks
- 0
01 前言 Front Matter
- name
- typescript-best-practices
- description
- TypeScript guidance. Use when writing or reviewing .ts or .tsx code.
02 资源文件 2
- 许可证LICENSE-pstack1.0 KB
- 参考文档references/patterns.md7.6 KB
03 SKILL.md 正文
TypeScript best practices
Apply type system discipline first. Follow the repository's compiler settings, schema libraries, and established type conventions. Apply these rules to the requested change.
| Rule | Summary |
|---|---|
| Schemas before guards | Before hand-writing a property-by-property type guard, use the repository's runtime schema library and infer the type from the schema, such as z.infer. |
| Type assertions | Prefer narrowing to assertions. Justify unavoidable assertions with validation or a demonstrated invariant. as const preserves literals; it does not validate external data. |
| Narrowing hierarchy | Discriminant switch > in operator > typeof/instanceof > user-defined type guard > as. |
| Type guards | Verify every property the predicate claims. Name guards isX or hasX. |
| Exhaustiveness | Inline const _exhaustive: never = x; in default arms so the compiler errors when a new variant is added. |
satisfies over as |
Check assignability without replacing the expression's inferred type with the target type. It supplies no runtime validation. |
| Schema-derived types | Reach for Pick/Omit/Parameters/ReturnType/Awaited/typeof before declaring a new interface. |
| Object args | Prefer named options where positional arguments are easy to confuse. Keep simple positional APIs and existing conventions when clear. Measure allocation concerns before changing a hot path. |
Read the relevant patterns for examples. The calling workflow owns verification, evidence reuse, and finding disposition. Optional style advice does not expand scope.
04 同仓库更多 Skills
replace-with-skill-name
Replace with when this skill should be reached.
writing-for-agents
Writing documents for agents. Use when creating or editing skills, or modifying AGENTS.md or CLAUDE.md.
worktree-cleanup
Worktree cleanup. Use for cleanup, resource audits, close this lane, or close out.
wizard
Generate an interactive Bash wizard that walks a human through steps only they can perform. Use when provisioning, credential setup, or a one-off migration needs such steps.
why
Use for 'why does X work this way', 'why we picked Y', design rationale, regressions, postmortems, or data-backed thresholds. Returns a cited read on decisions and tradeoffs.
wayfinder
Plan a huge chunk of work (more than one agent session can hold) as a shared map of decision tickets on your issue tracker, and resolve them one at a time until the way to the destination is clear.