AgentSkillsCN

api

为 TypeScript 库设计 API 并优化开发者体验。适用于设计 API、评审架构、评估开发者体验,或检查代码的人机工程学。涵盖可扩展性、渐进式披露、类型推断、状态模式,以及组件化设计。如需评审,请加载 review/workflow.md。触发时机:“设计 API”、“评审 API”、“检查开发者体验”、“是否符合人机工程学”、“评审架构”、“中间件设计”、“这种设计感觉如何”。

SKILL.md
--- frontmatter
name: api
description: >-
  API design and developer experience for TypeScript libraries. Use when designing
  APIs, reviewing architecture, evaluating DX, or checking ergonomics. Covers
  extensibility, progressive disclosure, type inference, state patterns, and
  composition. For review, load review/workflow.md.
  Triggers: "design API", "review API", "check DX", "is this ergonomic",
  "review architecture", "middleware design", "how does this feel".

API Design & Developer Experience

Principles for designing TypeScript library APIs and evaluating developer experience.

Goal: APIs should feel obvious, fast, safe, and composable — with great defaults and great escape hatches.

Quick Reference

Foundational

  • Emergent extensibility — Best extension points look like well-designed APIs, not plugin systems
  • Composition over configurationdevtools(persist(fn)) beats { middlewares: [] }
  • Onion model — Transformative middleware innermost, observational outermost

API Surface

  • Config objects for 3+ parameters (no overloads)
  • Flat returns for independent values, namespaced for cohesive units
  • Rule of two — Tuples for 2 values, objects for 3+
  • Inference over annotation — If users annotate, types aren't flowing

Progressive Disclosure

  • Complexity grows with use case — Zero-config → Options → Composition → Headless → Core
  • Escape hatches compose — Don't require reimplementing defaults
  • Explicit contracts — Render props over implicit requirements

Developer Experience

  • Time-to-first-success — Minimize time from install to working code
  • Cognitive load — Fewer concepts > fewer keystrokes
  • Predictable outcomes — Match user mental models
  • Editor ergonomics — TypeScript inference should just work

Conflict Resolution

When principles conflict, prioritize:

  1. Correctness — wrong behavior > verbose API
  2. Type Safety — inference failures > extra generics
  3. Simplicity — fewer concepts > fewer keystrokes
  4. Consistency — match existing codebase patterns
  5. Bundle Size — tree-shaking matters, but not at DX cost

Anti-Patterns

Anti-PatternWhy It Fails
Function overloadsPoor errors, autocomplete confusion
Runtime plugin registrationLoses type safety, implicit ordering
Positional parameters (3+)Order confusion, breaking changes
Implicit contractsSilent breakage when requirements unmet
Per-module middlewareUnexpected interactions
Shotgun parsingValidation scattered, not at boundaries
Boolean trapsfn(true, false) — what do these mean?
Multiple competing APIsConfusing — which method to use?

Reference Files

FileContents
references/principles.mdCore design and DX principles
references/typescript.mdType inference patterns (author + consumer)
references/state.mdState management patterns and architecture
references/extensibility.mdPipelines, builders, adapters, lifecycles
references/anti-patterns.mdCommon mistakes to avoid
references/libraries.mdReference libraries and their patterns
references/voices.mdPractitioner heuristics and reference URLs

Loading by Domain

DomainLoad
General API workprinciples.md
TypeScript/typestypescript.md
State managementstate.md
Middleware/pluginsextensibility.md
Avoiding mistakesanti-patterns.md
Library comparisonslibraries.md, voices.md

Review

For reviewing APIs and architecture, load review/workflow.md.

FileContents
review/workflow.mdReview process and checklists
review/agents.mdSub-agent prompts
review/templates.mdIssue format, report template
review/checklist.mdQuick single-agent checklist
review/example.mdComplete example review

Related Skills

NeedUse
Building UI componentscomponent skill
Accessibility patternsaria skill
Documentationdocs skill