1---2name: twoslash3description: Guides authoring and review of Twoslash-powered TypeScript docs examples, including hidden setup, type queries, completions, diagnostics, and multi-file snippets. Use when writing or reviewing `ts twoslash` fences or when docs examples need `---cut---`, `^?`, `^|`, `@filename`, or exact error assertions.4license: MIT5---67# Twoslash89Use for docs examples powered by Twoslash.1011## Scope and defaults1213- Prefer the smallest rendered snippet that still teaches the point.14- Keep setup imports, helper declarations, and fake files type-visible but reader-hidden with cut directives.15- Prefer `// @errors: ...` when the error itself is part of the lesson.16- Prefer `// @noErrors` only when the snippet is intentionally incomplete for some other reason, such as completion demos.17- Prefer `// @filename:` for multi-file context instead of explaining missing imports in prose.18- Prefer `// @showEmit` only when the emitted JS, `.d.ts`, or map file is the teaching target.19- Do not reach for this skill for plain TypeScript snippets that do not rely on Twoslash behavior.2021## Gotchas2223- `^?`, `^|`, and `^^^` always apply to the previous line.24- Do not eyeball marker spacing like `// ^|`; use `uv run scripts/inspect-markers.py <file>` or another column-aware tool to count columns.25- Hidden code still participates in type checking and editor metadata; prefer cutting setup over deleting it.26- `@filename:` stays visible unless you cut it away on purpose.27- `@showEmittedFile` is only meaningful together with `@showEmit`.2829## Fast triage3031```txt32What does the user need?33├─ Show an inferred type or resolved symbol34│ └─ references/notations.md -> query markers35├─ Show autocomplete or highlight a span36│ └─ references/notations.md -> query markers37├─ Hide setup, fixtures, or boilerplate38│ └─ references/patterns.md -> hidden-setup patterns39├─ Model multiple files or fake imports40│ └─ references/patterns.md -> multi-file patterns41├─ Show or validate diagnostics42│ └─ references/notations.md -> error flags43├─ Show emitted JS / .d.ts / source maps44│ └─ references/notations.md -> emit flags45└─ Explain provenance or edge options46 └─ references/source-index.md47```4849## Response workflow50511. Identify whether this is new authoring or review of an existing snippet.522. Identify the teaching goal: type, completion, highlight, hidden setup, diagnostics, or emit.533. Keep the rendered sample minimal; move scaffolding into cut regions or virtual files.544. Add the smallest directive set that proves the point.555. If errors are intentional, prefer exact validation with `@errors` over blanket suppression.566. If the snippet is multi-file or emit-focused, verify the visible file is the one the reader actually needs.577. Name the exact directives in the answer so the user can copy them directly.5859## Authoring defaults6061- `^?` for inferred or resolved types.62- `^|` for completion lists; pair with `@noErrors` when the expression is intentionally unfinished.63- `^^^` for visual emphasis, not semantic explanation.64- `---cut---` or `---cut-before---` to hide setup above the visible snippet.65- `---cut-after---` or `---cut-start---` / `---cut-end---` to hide trailing or middle noise.66- `@filename:` to create virtual files, including fake `node_modules/@types` shims.6768## Reading Order6970| Task | Files to read |71| ----------------------------------------- | ------------------------------------------------------------------------- |72| New to Twoslash authoring | [`SKILL.md`] -> [`references/notations.md`] -> [`references/patterns.md`] |73| Pick the right directive | [`references/notations.md`] |74| Copy a known-good shape | [`references/examples.md`] |75| Hide fixtures or multi-file setup | [`references/patterns.md`] |76| Explain lesser-used options or provenance | [`references/source-index.md`] |77| Do a wider upstream docs sweep | [`example-docs.txt`] -> [`references/source-index.md`] |78| Run or inspect evals | [`evals/README.md`] -> [`scripts/run-evals.py`] |79| Check marker alignment | [`scripts/inspect-markers.py`] |80| Review a noisy or broken snippet | [`references/patterns.md`] -> [`references/notations.md`] |8182## Scripts8384| Script | Purpose |85| ------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------- |86| [`scripts/run-evals.py`] | Runs response-quality evals and trigger checks against the Twoslash skill |87| [`scripts/inspect-markers.py`] | Prints real line/column counts for `^?`, `^^^`, `^\|` markers. (NOTE: IN , `^\|` THE SLASH IN FRONT OF THE PIPE IS ONLY HERE FOR MARKDOWN ESCAPING) |8889## In This Reference9091| File | Purpose |92| ------------------------------ | --------------------------------------------------------------- |93| [`references/notations.md`] | Exact notation names, flags, and when to use them |94| [`references/examples.md`] | Small copy-paste examples for common Twoslash patterns |95| [`references/patterns.md`] | Authoring defaults, hidden-setup patterns, and review checklist |96| [`references/source-index.md`] | Upstream source URLs and provenance notes |97| [`example-docs.txt`] | Local `gitingest` snapshot of upstream Twoslash docs |98| [`evals/README.md`] | How to run the regression harness and read its outputs |99100[`references/notations.md`]: ./references/notations.md101[`references/examples.md`]: ./references/examples.md102[`references/patterns.md`]: ./references/patterns.md103[`references/source-index.md`]: ./references/source-index.md104[`example-docs.txt`]: ./example-docs.txt105[`evals/README.md`]: ./evals/README.md106[`scripts/run-evals.py`]: ./scripts/run-evals.py107[`scripts/inspect-markers.py`]: ./scripts/inspect-markers.py108[`SKILL.md`]: ./SKILL.md