api

设计直观且安全的 TypeScript 库 API,强调组合性与渐进式复杂度管理,通过类型推导降低使用成本,确保开发者能快速上手并灵活扩展,同时避免常见设计陷阱以提升整体开发体验。

快捷安装

在终端运行此命令,即可一键安装该 Skill 到您的 Claude 中

npx skills add videojs/v10 --skill "api"

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
NeedUse
Building UI componentscomponent skill
Accessibility patternsaria skill
Documentationdocs skill