Writing Guides
A guide teaches one module and shows where it sits in a larger program. A reference page answers “what does this function do”; a guide answers “when do I reach for this module, and what do I hand off to next”.
This page is the public writing standard. The module authoring guide covers code structure; Testing covers tests.
Anatomy
Section titled “Anatomy”Keep the bundle badge byte-identical. pnpm size:update owns the number; the bundle-size test fails
on drift. Never add a second badge.
Opening
Section titled “Opening”Describe one scene and the concrete failure before naming a library type. The reader should recognize the problem first.
Good:
A thumbnail worker reads its queue URL from an environment variable. When the variable is absent, the worker starts with the string
undefinedand fails on the first job.
Avoid announcing the page or listing several unrelated scenarios. One subject, one action, one consequence.
Core Behavior
Section titled “Core Behavior”Define the type in one sentence, then give two to four behavior bullets: short-circuiting, ordering,
boundary safety, and cancellation. Close the section with one nearest alternative and a link to
/basics/choosing/. Do not turn the paragraph into a menu of every related module.
Example and handoff
Section titled “Example and handoff”Keep one domain from the opening through the handoff. Use a vertical Mermaid diagram that shows only
the transitions the module controls. Then show a complete implementation with real interfaces, real
error types, and pipe(...).
End the example with one ### handoff subsection that takes the same feature one step into an
adjacent module: Result to Task.Result, Validation to a Result boundary, Graph to
Transaction, or Lens to Optional. The handoff shows the seam; it does not re-teach the next
module.
Core Operations
Section titled “Core Operations”Group operations by intent: Creating, Combining, Transforming, Running, Reading, or Converting. Use a table with the signature, what it does, and the return type. Split a table by intent rather than letting it grow into a wall.
Failure Behavior and Edge Cases
Section titled “Failure Behavior and Edge Cases”Document exception boundaries, cancellation, ordering, clamping, and callback contracts. Link a
sibling guide when a failure belongs to it, such as Aborted for cancellation. Do not restate
ordinary TypeScript semantics.
Every public export needs:
- A one-line plain-English description.
- A realistic
@example, notfoo(bar)or a type puzzle. - Reciprocal
@seelinks for complementary operations:mapandchain,traverseandsequence,tapandtapError,from.*andto.*.
Keep fetch out of base Task examples. Use it in Task.Result, Task.Maybe, or Op instead.
Cross-links and voice
Section titled “Cross-links and voice”Every guide carries at least two inline links: one in the placement paragraph and one in the
handoff. Async guides link to /basics/types/. Any guide that mentions cancellation links to
/guides/aborted/.
Write for a TypeScript developer with three years of experience and no functional-programming background. Replace “declarative lifecycle bracket” with “pairs setup with cleanup”; replace “catamorphism” with “named-case matching”. No promotional adjectives, no “in essence”, no “not only … but also”.
Typography and diagrams
Section titled “Typography and diagrams”- Use spaced em dashes.
- Do not use LaTeX delimiters.
- Use vertical
flowchart TDorstateDiagram-v2diagrams withdirection TB. - No HTML inside labels. Use parentheses for type parameters:
Result.Ok(A). - Quote labels with punctuation.
- No
noteblocks in state diagrams.
Complete example
Section titled “Complete example”Checklist
Section titled “Checklist”- The opening states the situation and failure before naming a type.
-
Core Behaviorends with one nearest sibling and/basics/choosing/. - The example keeps one domain and includes the diagram, implementation, and handoff.
-
Core Operationsis grouped by intent. -
Failure Behavior and Edge Casesis specific. - At least two inline documentation links are present.
- The bundle badge appears exactly once.
- No numbered headings, LaTeX, banned phrases, or “Problems it solves” appendix.
-
pnpm formatandpnpm docs:buildpass.
Run pnpm check:docs before opening a docs pull request; it checks formatting, links, marked
snippets, bundle metadata, and the Astro build.