trove-typescript
TypeScript type-system discipline for any .ts/.tsx file: make illegal states unrepresentable, validate at boundaries, avoid as/any. Use when reading or editing TypeScript that isn't covered by a framework-specific skill. Defers to trove-react / trove-react-best-practices on .tsx component work. Use when: typescript best practices; type this correctly; make illegal states unrepresentable.
- License 许可
- MIT
- 所属仓库
- bravew/trove
- 最近更新
- 2026-11-12
- Stars
- ★ 10
- Forks
- 1
01 前言 Front Matter
- name
- trove-typescript
- description
- TypeScript type-system discipline for any .ts/.tsx file: make illegal states unrepresentable, validate at boundaries, avoid as/any. Use when reading or editing TypeScript that isn't covered by a framework-specific skill. Defers to trove-react / trove-react-best-practices on .tsx component work. Use when: typescript best practices; type this correctly; make illegal states unrepresentable.
02 资源文件 1
- 参考文档references/patterns.md3.0 KB
03 SKILL.md 正文
<!-- AUTO-GENERATED from SKILL.md.tmpl — do not edit directly --> <!-- Regenerate: bun run build:skills -->
Session Init
This skill ships Trove conventions. Prefer existing project patterns over generic best practices when they conflict.
If a sibling skill in this plugin matches the request more directly, defer to it. See AGENTS.md (or docs/routing.md in the marketplace) for the per-plugin routing index.
TypeScript Type-System Discipline
The type checker is a proof assistant. Model the domain so wrong states don't compile. On .tsx, defer to trove-react / trove-react-best-practices for component patterns; this skill owns the plain type discipline underneath them.
Core rules
| Rule | Do | Not |
|---|---|---|
| Illegal states | Discriminated union with a kind/status tag |
boolean + optional field pairs |
| Identity | Branded primitives (string & { readonly __brand: 'UserId' }) |
bare string for ids |
| External data | unknown + parse at the boundary |
any |
| Casts | satisfies to check shape while keeping literals |
as SomeType |
| Exhaustiveness | const _exhaustive: never = x in the default branch |
unhandled union members |
| Type guards | Guards that actually narrow and are verified | x as Foo inside the guard |
| Derive | Types derived from a schema (Zod/valibot infer) |
hand-kept parallel types |
The canonical example
// BAD — admits the meaningless { completed: true, completedAt: undefined }
type Task = { completed: boolean; completedAt?: Date };
// GOOD — the bad state cannot be constructed
type Task =
| { status: 'open' }
| { status: 'done'; completedAt: Date };
Boundaries
Validate once, at the edge (network, config, user input). Past the boundary, trust your domain types and keep logic pure. "Parse, don't validate": a parser returns a more precise type or fails; it doesn't just check and discard what it learned.
function parseUser(raw: unknown): User {
return UserSchema.parse(raw); // unknown -> User, or throws at the boundary
}
See references/patterns.md for the full pattern set with worked examples.
AI Gotchas
asto silence an error hides the bug you'll debug next week. Reach for narrowing orsatisfiesfirst.anyon external data erases the boundary. Useunknownand parse.- Non-exhaustive
switchover a union compiles today and breaks when a variant is added. Add theneverguard. - Parallel hand-maintained types drift. Derive from the schema.
04 同仓库更多 Skills
using-trove
Skill discipline anchor for the Trove marketplace. Loaded once per session; routes the agent to the right trove-* skill before code, planning, review, or git actions.
trove-write-skill
Skill authoring workflow. Use when creating or updating a Codex or Trove skill, including rubrics, tasks, metadata, and validation.
trove-worktree
Git worktree workflow for spikes, risky experiments, and broad refactors that should not disturb the user's current branch.
trove-why
Reconstruct design rationale and decision history from evidence — source control, issue tracker (Linear), docs (Notion), chat (Slack), error tracking (Sentry) — with calibrated confidence. Use for "why does X work this way", "why did we pick Y", regressions, and postmortems. Use trove-explain for how it works now.
trove-verify
Completion verification workflow. Use before claiming done, fixed, complete, ready, or shipped.
trove-unslop
Cut AI tells from writing — PR descriptions, release notes, specs, commit bodies, and replies. Use before finalizing prose, or when the user asks to clean up, de-slop, or make text sound human.