On this page
The short answerWhere TypeDoc examples liveBuild a small referenceCheck an include failureScan the Markdown pagesExtract examples for the compiler and scanTest a renamed exportTriage and coverageThe sources we checkedFAQThe short answer
Use TypeDoc to build and validate the reference, TypeScript to check extracted examples, and a docs scan to run supported examples and triage failures. TypeDoc renders examples but does not compile or run them. In engine 0.6.3, DocsAlive does not detect TypeDoc as a framework or read source doc comments. For this project it scans docs/ plus the root README, strips simple TypeScript annotations and runs the result with Node; richer syntax is skipped as not judged. A renamed export in a ts fence is reported as not judged, while the same missing export in a js fence is reported as invalid-syntax.
That division matters because a successful reference build proves that TypeDoc could produce the documentation, not that a reader can import the names shown in it. The example workflow below uses TypeDoc’s own JSON to make comment examples available to a compiler and a scan. It also keeps a separate scan of the original project documents.
The package acme-version is illustrative and is not a published package. The files below form a small example project; adapt the paths and exported names to your repository. For the broader JavaScript and TypeScript context, see testing TypeScript documentation examples and testing JavaScript documentation examples.
Where TypeDoc examples live
An example tag marks the text after it as an example. A tag can contain a fenced code block with explanatory text outside the fence. If there is no code block in the tag, TypeDoc treats the whole tag as a code block. That bare form is recognized by VS Code even though it is not valid TSDoc. A checker that searches only Markdown fences in source files can therefore miss both comment examples and bare examples.
An inline includeCode tag inserts an external file inside a code block and uses the file suffix to choose the highlighting language. The include tag instead inserts external Markdown into a comment. Both can select named regions, several comma-separated regions, or line numbers. In TypeScript and JavaScript files, named regions use region and end-region comments. Paths use forward slashes. TypeDoc warns that line-number references are likely to break when a file changes, so a named region is usually a more durable way to identify an excerpt.
An excerpt has a second risk: it may omit the import or setup that makes the complete source file runnable. A region can render exactly the intended two lines and still fail when copied into a fresh environment. Decide whether the published example should include its own setup or whether a test must supply documented context.
TypeDoc can also bring in project documents through a document tag, the projectDocuments option, or children listed in a document’s YAML front matter. Documents can have title, group, category and children front matter. The readme option selects the readme shown on the index page; setting it to none disables it. Entry points and the entry-point strategy determine the API material TypeDoc processes; resolve is the default strategy. When project documents are used, alwaysCreateEntryPointModule defaults to true.
Build a small reference
First install the tools used in this illustrative project. The versions resolved in the verification were TypeDoc 0.28.20 and TypeScript 6.0.3.
npm install --save-dev typedoc typescript
The package manifest exposes the built file. Node supports referencing a package by its own name from within that package when its exports are configured, so the examples can use the same import shape a reader would use.
{
"name": "acme-version",
"version": "1.0.0",
"type": "module",
"exports": "./dist/index.js",
"scripts": {
"build": "tsc",
"docs": "typedoc"
},
"devDependencies": {
"typedoc": "^0.28.20",
"typescript": "^6.0.3"
}
}
This TypeScript configuration emits declarations as well as JavaScript. The explicit rootDir is significant for this verified setup: TypeScript 6.0.3 refused the build without it.
{
"compilerOptions": {
"target": "ES2022",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"declaration": true,
"rootDir": "src",
"outDir": "dist",
"strict": true
},
"include": ["src"]
}
The illustrative TypeDoc configuration adds Markdown files in docs/ as project documents and makes warnings fatal. That setting is valuable for unresolved links and other warnings, but it does not turn examples into executable tests.
{
"entryPoints": ["src/index.ts"],
"projectDocuments": ["docs/*.md"],
"out": "site",
"treatWarningsAsErrors": true
}
The source file demonstrates three different example locations: a fenced example, a bare example, and an included region. The code and package name are illustrative.
/**
* Parse a version string such as "2.4.1" into its three numbers.
*
* @example
* ```ts
* import { parseVersion } from "acme-version";
* console.log(parseVersion("2.4.1"));
* ```
*/
export function parseVersion(text: string): [number, number, number] {
const parts = text.trim().split(".").map(Number);
if (parts.length !== 3 || parts.some((n) => !Number.isInteger(n) || n < 0)) {
throw new Error(`not a version: ${text}`);
}
return [parts[0], parts[1], parts[2]];
}
/**
* Compare two version strings. Returns -1, 0 or 1.
*
* @example
* import { compareVersions } from "acme-version";
* compareVersions("2.4.1", "2.10.0"); // -1
*/
export function compareVersions(a: string, b: string): number {
const x = parseVersion(a);
const y = parseVersion(b);
for (let i = 0; i < 3; i++) {
if (x[i] !== y[i]) return x[i] < y[i] ? -1 : 1;
}
return 0;
}
/**
* Build the URL of a host. See {@link parseVersion} for version strings.
*
* {@includeCode ../examples/connect.ts#connect}
*/
export function connect(host: string, port = 443): string {
return `https://${host}:${port}`;
}
The included file is runnable as a whole, but the selected region starts after the import. The rendered excerpt therefore needs context if it is copied into a standalone test.
import { connect } from "acme-version";
//#region connect
const url = connect("localhost", 8443);
console.log(url);
//#endregion connect
The project document below contains both TypeScript and JavaScript. Its tuple annotation is deliberately useful for demonstrating the engine’s TypeScript limit: the compiler can understand it, while the engine’s simple annotation stripping cannot.
---
title: Getting started
---
# Getting started
Parse a version and keep the result typed:
```ts
import { parseVersion } from "acme-version";
const v: [number, number, number] = parseVersion("2.4.1");
console.log(v[1]);
```
Sort a list of versions:
```js
import { compareVersions } from "acme-version";
const sorted = ["2.10.0", "2.4.1", "1.0.0"].sort(compareVersions);
console.log(sorted.join(" "));
```
The root README is another reader-facing page and is included on the index in this setup.
# acme-version
Parse and compare version strings.
```ts
import { compareVersions } from "acme-version";
console.log(compareVersions("1.0.0", "1.0.0"));
```
Build the package before building the reference. In the verification, both commands succeeded. The reference showed the two comment examples and the two selected region lines; the import above the region was absent.
npx tsc
npx typedoc
A successful build does not mean every example has been type-checked. TypeDoc’s validation has a different job. Its defaults enable checks including unresolved link tags and invalid paths; notDocumented is off by default. treatWarningsAsErrors makes warnings fatal, while treatValidationWarningsAsErrors applies to validation warnings specifically. Keep those checks enabled as appropriate, but add example checks independently.
Check an include failure
This change is broken on purpose: it asks for a region that is not present.
- * {@includeCode ../examples/connect.ts#connect}
+ * {@includeCode ../examples/connect.ts#connect-url}
TypeDoc reported the missing region as an error and exited with status 4. It did so with treatWarningsAsErrors both enabled and disabled. This is a useful build guard, but it verifies that the region exists, not that its contents run.
[error] @includeCode tag in index.connect specified "../examples/connect.ts#connect-url" to include from file "examples/connect.ts" the region labeled "connect-url", but the region was not found in the file.
[error] Found 1 errors and 0 warnings
Restore the correct region before continuing. When an include builds successfully, inspect what readers actually receive: a valid region can still omit imports or reference a name that has changed.
Scan the Markdown pages
The following command plans a scan; execution requires the CLI’s execution option. In the verified run after the package build, the default plain-project scope covered two pages and three blocks: the README TypeScript block and the getting-started JavaScript block passed, while the tuple-typed block was skipped as unsupported syntax. None of the three source-comment examples was read.
docsalive scan .
The distinction between planning and execution is important when interpreting a report. A planned block has been found and classified for a possible check; it has not necessarily run. The CLI reference describes execution, setup and report options at /docs/cli/.
| TypeDoc item | What TypeDoc does | What the engine does in 0.6.3 |
|---|---|---|
| Fenced example in a source comment | Renders the example | Does not read the comment |
| Bare example in a source comment | Treats the whole tag as a code block | Does not read the comment |
| Included code region | Expands and renders the selected region; fails if the region is missing | Does not read the source comment or resolve the include |
Project document in docs/ |
Adds it to the reference when configured | Scans its Markdown under the default scope |
| Root README | Can show it on the index | Scans it alongside docs/ |
| TypeScript fence | Renders it | Strips simple annotations and runs with Node; unsupported syntax is not judged |
| JavaScript fence | Renders it | Runs it with Node |
| Link validation | Warns for unresolved link tags; warnings can be fatal | Does not replace TypeDoc’s validation |
Extract examples for the compiler and scan
The following illustrative script reads TypeDoc’s JSON output. In the verified output, the bare example had already become a TypeScript fence, and the included region had already been expanded into one. The script writes comment examples to a Markdown page and writes TypeScript examples from comments, project documents and the readme to separate files for the compiler.
It adds an import listing exported names when an example has no import from the package. That makes the selected region testable in this particular project, but it is an assumption to review: a generated import can supply context missing from the published excerpt.
"""Copy the code examples TypeDoc documents into files that can be scanned and type-checked.
Run `npx typedoc --json api.json` first. TypeDoc's JSON holds each @example
as a fenced code part (bare @example text is already wrapped as ts) and each
includeCode region already expanded.
Writes scan-docs/api/examples.md (examples from doc comments, for a docs scan)
and scan-docs/typecheck/*.ts (every ts example: comments, project documents
and the readme, for tsc --noEmit).
"""
import json
import re
import shutil
import sys
from pathlib import Path
api = json.loads(Path(sys.argv[1]).read_text())
out = Path(sys.argv[2])
package = json.loads(Path("package.json").read_text())["name"]
FENCE = re.compile(r"^```(\w*)\n(.*?)\n```$", re.S)
def walk(refl):
for child in refl.get("children", []):
yield child
yield from walk(child)
# Names a reader can import (kind 2 is a module and 4 a namespace).
exported = [r["name"] for r in walk(api) if r["kind"] not in (2, 4)]
prelude = "import { " + ", ".join(exported) + ' } from "' + package + '";\n'
def fences(parts):
for part in parts:
if part["kind"] == "code":
m = FENCE.match(part["text"].strip())
if m:
yield (m.group(1) or "ts"), m.group(2)
def comment_parts(refl):
parts = []
for c in [refl.get("comment")] + [s.get("comment") for s in refl.get("signatures", [])]:
if c:
parts += c.get("summary", [])
for tag in c.get("blockTags", []):
if tag["tag"] == "@example":
parts += tag["content"]
return parts
def with_import(code):
# An includeCode region often leaves out the import line.
return code if f'from "{package}"' in code else prelude + code
page = ["# API examples", ""]
typecheck = []
for refl in walk(api):
for lang, code in fences(comment_parts(refl)):
if lang in ("ts", "js"):
code = with_import(code)
page += [f"## {refl['name']}", "", f"```{lang}", code, "```", ""]
if lang == "ts":
typecheck.append((refl["name"], code))
for doc in api.get("documents", []):
typecheck += [(doc["name"], c) for lang, c in fences(doc["content"]) if lang == "ts"]
typecheck += [("readme", c) for lang, c in fences(api.get("readme", [])) if lang == "ts"]
shutil.rmtree(out, ignore_errors=True)
(out / "api").mkdir(parents=True)
(out / "api" / "examples.md").write_text("\n".join(page))
(out / "typecheck").mkdir()
for n, (name, code) in enumerate(typecheck, 1):
slug = re.sub(r"\W+", "-", name).strip("-").lower()
# export {} makes each file a module, so names do not clash between files.
(out / "typecheck" / f"{n:02d}-{slug}.ts").write_text(code + "\nexport {};\n")
print(f"wrote {out / 'api' / 'examples.md'} and {len(typecheck)} files in {out / 'typecheck'}")
Use a separate compiler configuration for the generated examples. In this verification, TypeScript 6.0.3 refused a command that supplied file names while a project configuration existed, so the separate project file also makes the intended input explicit.
{
"extends": "./tsconfig.json",
"compilerOptions": {
"noEmit": true,
"rootDir": "."
},
"include": ["scan-docs/typecheck"]
}
Build the package first so its declaration files exist, then generate TypeDoc JSON, regenerate the copy and type-check it. The scan command shown here plans the generated page; use execution when you want the examples run. In the verified execution, the generated scope contained the README and generated API page: four blocks were run and all four passed.
npx typedoc --json api.json
python3 tools/typedoc_scan_copy.py api.json scan-docs
npx tsc -p tsconfig.examples.json
docsalive scan . --docs-dir scan-docs
The script reported the generated page and five TypeScript files:
wrote scan-docs/api/examples.md and 5 files in scan-docs/typecheck
There are several boundaries to preserve in CI. The script needs a successful TypeDoc JSON run first. It understands ts and js fences for its import handling; other languages are copied to the page but are not type-checked. The added import lists every exported name and assumes the package can import itself by name. It cannot find examples TypeDoc did not document, including private or excluded items.
The generated Markdown page contains comment examples only. With --docs-dir scan-docs, the ordinary docs/ folder is not read, so retain the default scan for project documents. The compiler check does not execute the generated files. The scan executes TypeScript only after simple annotation stripping, so richer syntax can be skipped as not judged. Regenerate scan-docs in CI rather than editing it by hand.
Test a renamed export
This change is broken on purpose: it renames an export while leaving its examples and the README unchanged.
-export function compareVersions(a: string, b: string): number {
+export function compare(a: string, b: string): number {
The package build and TypeDoc build still succeeded. The getting-started JavaScript fence failed as invalid-syntax because Node reported the missing named export as a syntax error. The stale TypeScript examples in the README and generated page were skipped as unsupported syntax, not judged as documentation bugs. The compiler supplied the missing signal and exited with status 2:
scan-docs/typecheck/01-compare.ts(1,10): error TS2724: '"acme-version"' has no exported member named 'compareVersions'. Did you mean 'parseVersion'?
scan-docs/typecheck/05-readme.ts(1,10): error TS2724: '"acme-version"' has no exported member named 'compareVersions'. Did you mean 'parseVersion'?
This is why the recommended layers are complementary: TypeDoc validates the reference and its links; the compiler checks extracted TypeScript against declarations; the scan runs supported Markdown examples and helps triage what happened. A passing layer should not be interpreted as coverage from the other two.
Triage and coverage
| Finding | Likely cause | What to do |
|---|---|---|
| TypeDoc reports a missing region | The region name or path changed | Restore the intended region or update the include, then inspect the rendered excerpt |
| Link warning becomes fatal | A link target cannot be resolved or another warning was emitted | Correct the target or investigate the warning before relaxing validation |
| Compiler reports a missing export | An example still imports an old API name | Compare the example with the intended public API and update it or restore compatibility |
| TypeScript block is not judged | Syntax could not be stripped, or Node reported a syntax error including a missing named export | Run the compiler check and inspect the original example |
| JavaScript block reports invalid-syntax after a rename | Node reported a missing named export as a syntax error | Check the import against the built package |
| Generated region fails for an undefined name | The region omitted context | Make the reader-facing excerpt self-contained or document and test its prerequisite |
Read every skip with its reason, not just the totals. A block skipped as unsupported syntax was not judged at all, so it is a coverage gap, not a pass. In this project the compiler check narrows that gap: a block the scan cannot strip is still type-checked in full by the compiler, although the compiler does not run it. Bash install lines in a README are a separate case: they need the network, and when a scan runs with the network off they are skipped rather than run. Keep a short note in the pull request when a skip is expected, so a reviewer can tell a known gap from a new one.
Use this checklist in a review or CI task:
[ ] Build the package and its declarations.
[ ] Build TypeDoc with the desired validation warnings made fatal.
[ ] Check that included regions contain the context readers need.
[ ] Generate TypeDoc JSON and regenerate scan-docs.
[ ] Type-check the extracted TypeScript examples.
[ ] Run the default docs and README scan.
[ ] Run the generated comment-example scan.
[ ] Review skipped and unsupported blocks as coverage gaps.
[ ] Check changed exports against examples before release.
DocsAlive fits the execution and triage layer. It can run supported blocks in page order and report findings with their context, but it does not inspect TypeDoc comments directly or replace a full TypeScript compiler. See findings, API reference testing, and pre-commit docs testing for adjacent checks.
The sources we checked
These sources were read on November 15, 2026. Engine behavior was checked against engine 0.6.3 on the same day.
| Source | What it covers |
|---|---|
| TypeDoc example tag | Fenced and bare example text |
| TypeDoc include tags | External content, regions and line references |
| TypeDoc external documents | Project documents and front matter |
| TypeDoc input options | Entry points, project documents and readme |
| TypeDoc validation options | Validation and fatal warnings |
| Node packages | Package exports and self-reference |
FAQ
Does TypeDoc run its examples?
No. It renders examples and validates aspects of the reference, but it does not compile or execute example code. Add a compiler check and an execution layer for that evidence.
What does DocsAlive read in this TypeDoc project?
In engine 0.6.3 it does not detect TypeDoc or read doc comments. With a top-level docs folder it scans that folder plus the root README. It strips simple TypeScript annotations before running with Node; unsupported syntax is skipped as not judged.
Will a renamed export be caught in a TypeScript fence?
The verified missing export surfaced as a Node syntax error and was skipped as unsupported syntax, not judged. The same missing export in a JavaScript fence was reported as invalid-syntax. Type-check extracted TypeScript examples with the compiler.
Why did an included region fail as a standalone example?
The selected lines may omit an import or other setup outside the region. Review the rendered excerpt and either include the necessary context or document the prerequisite. A generated test import can hide that reader-facing gap.
Does a successful TypeDoc build verify included code?
TypeDoc fails when a named includeCode region is missing, but an existing region can still contain stale or nonworking code. A successful build does not compile or run its contents.
Should the generated scan page be edited by hand?
No. Regenerate it from the current TypeDoc JSON in CI. Keep the ordinary scan too, because the generated scope does not include the original docs folder.




