typescript-style
Opinionated style guide for strict, portable TypeScript. Use when writing, designing, or reviewing TypeScript: type design, boundary validation, error handling, module architecture, and review discipline.
- License 许可
- MIT
- 所属仓库
- nseng-ai/ns
- 最近更新
- 2026-10-02
- Stars
- ★ 2
- Forks
- 0
01 前言 Front Matter
- name
- typescript-style
- references
- [ "core-rules", "idioms", "checklist", "references/README", "references/philosophy", "references/type-system", "references/error-handling", "references/case-study-backend-neutrality", "references/case-study-context-management", "references/case-study-extension-system", "references/case-study-tui", "references/review-taste-and-process" ]
- description
- Opinionated style guide for strict, portable TypeScript. Use when writing, designing, or reviewing TypeScript: type design, boundary validation, error handling, module architecture, and review discipline.
02 资源文件 12
- 参考文档checklist.md7.7 KB
- 参考文档core-rules.md22.4 KB
- 参考文档idioms.md9.2 KB
- 参考文档references/case-study-backend-neutrality.md4.3 KB
- 参考文档references/case-study-context-management.md4.0 KB
- 参考文档references/case-study-extension-system.md3.9 KB
- 参考文档references/case-study-tui.md4.1 KB
- 参考文档references/error-handling.md7.6 KB
- 参考文档references/philosophy.md5.5 KB
- 参考文档references/README.md1.8 KB
- 参考文档references/review-taste-and-process.md6.1 KB
- 参考文档references/type-system.md6.4 KB
03 SKILL.md 正文
typescript-style
An opinionated TypeScript style guide for strict, maintainable projects. It sets portable code-level and compiler-level defaults. Project-specific choices such as package managers, formatters, CI wiring, test runners, and import suffixes belong in the local repository or a project overlay skill.
Keep Zod as the default runtime validation library for new external boundaries unless the project has already chosen otherwise.
Scope
Use this as a reference for:
- strict type design with Zod boundary schemas, string-literal unions, discriminated unions, generics,
and
satisfies; - choosing
interfacevs.type,throwvs. returned errors, and core vs. plugin/adapter boundaries; - designing backend-neutral abstractions, stateful runtimes, extension/plugin APIs, and terminal UIs;
- reviewing TypeScript for needless machinery, incoherent types, hidden globals, and unowned complexity.
Core knowledge
Read core-rules.md first. It contains the default rules and when to bend them for project-local
constraints.
For copy-paste idioms while coding, read idioms.md. Before finishing implementation or review,
run checklist.md.
One-paragraph version
Write strict, erasable TypeScript: no enum, no namespace, and no parameter properties in new code.
Closed sets are string-literal unions; runtime variants are discriminated unions using type by
default, with domain/external tags only when they better express the model. Use unknown at boundaries
and avoid any except isolated, commented library-forced seams. Validate external boundaries with Zod
schemas and derive types with z.infer. Encode expected failure as returned data at async/system
boundaries (Result<T,E>, terminal error events); throw only for programmer errors and broken
invariants. Top-level module logic uses function declarations; callbacks and expression-position
factories can use arrows. Prefer guard clauses and nullish operators for nullish semantics. Keep a
small, clearly ordered set of required core data and dependencies as direct inputs; use named options
objects for behavioral configuration and long input lists. Respect ownership-boundary immutability: do
not mutate inputs, returned values, or shared/public state in place. Keep the core minimal: optional behavior lives behind
plugins, adapters, or capability flags. Functions do logic; classes coordinate state. Inline one-use
helpers. Suppressions and empty catches explain why. Be direct in reviews and comments; explain why, not
mechanics.
Conditional loading
Top-level files (core-rules.md, idioms.md, checklist.md) are optimized for everyday work. The
references/ folder holds deeper rationale and worked examples. Load only the relevant reference.
| Situation | Read |
|---|---|
| Need the rationale behind a rule, or to justify a review comment | references/philosophy.md |
Designing types: unions, generics, satisfies, declaration merging, why no enums |
references/type-system.md |
Designing failure handling: errors-as-values, Result, typed errors, cancellation |
references/error-handling.md |
| Building a backend/provider abstraction or anything multi-backend | references/case-study-backend-neutrality.md |
| Building a stateful workflow, context manager, compaction, or scheduling loop | references/case-study-context-management.md |
| Building an extension/plugin system, tool registry, or SDK surface | references/case-study-extension-system.md |
| Building a TUI, renderer, component model, or keybinding system | references/case-study-tui.md |
| Reviewing a PR or writing terse implementation feedback | references/review-taste-and-process.md |
references/README.md is the index of the reference folder.
How to apply this skill
- Load
core-rules.mdbefore changing code. - If the project has an established convention that conflicts with this guide, follow the project and mention the deviation only if it matters.
- When a domain matches, load the matching reference before designing the abstraction.
- When making a judgment call, prefer the smallest coherent design that keeps types honest end to end.
- Run
checklist.mdbefore declaring the work done.
04 同仓库更多 Skills
pr-make-accountable
Interview a PR author to establish shared understanding of intent and design decisions, then co-author the What / Why / Changes PR body with opt-in Requested reviewer focus.
typescript-fake-driven-testing
TypeScript fake-driven testing architecture. Use when writing or reviewing TS code with external dependencies, gateway interfaces, real adapters, in-memory fakes, or CLI scenario tests.
ns-typescript
TypeScript overlay for ns-style projects. Use when editing or reviewing TS in this repo: tsconfig baseline, pnpm/Vitest/oxlint/oxfmt/native tsc commands, relative .ts imports, workspace subpath exports, and the exactOptionalPropertyTypes spread idiom. Repo-specific enforcement (test lanes, time seams, style guard) lives in the host repo's AGENTS.md.
ns-typescript-style-tripwire
Invoke the ns TypeScript style Tripwire against a supplied diff or current branch.
skill-management
Manage skills with `npx skills`: add, edit, remove, rename, update, or list skills (local or GitHub), and the nested `skills/<disposition>/.../<name>/` / flat `.agents/skills/` layout conventions.
review-thermonuclear-review
Invoke the Thermonuclear Review review against a supplied diff or current branch.