Installation
Requirements
TypeDoc requires Node.js to be installed on your system. If you haven't done that already, head over to their site and follow their install instructions.
Installing TypeDoc is available as a node package. Using npm
ensures that all relevant
dependencies are setup correctly. You can choose to either install locally to your project or
globally to the CLI.
Local installation (preferred)
If you want to use TypeDoc from your command line in a project, use the API in your project code, or TypeDoc in an npm script, a local installation is the recommended approach. First install TypeDoc locally in your project:
$ npm install typedoc --save-dev
By saving TypeDoc to the project package.json
file with the previous command,
anyone who runs npm install
on the project will have typedoc installed at the specific version required for the project.
The name of TypeDoc's executable is typedoc
. To verify that it works, you can now invoke the CLI in your project using npx
(npx
is a tool bundled with npm
), passing TypeDoc the --version
argument:
$ npx typedoc --version
TypeDoc 0.20.0
Using TypeScript 4.1.2 from /home/gerrit/typedoc/node_modules/typescript/lib
Command line interface
The CLI can be used both from your terminal or from npm scripts. All arguments that are not passed
with flags are parsed as entry points. Use either the --out
or --json
arguments to define the format and destination of your documentation.
typedoc --out docs src/index.ts
JSON Configuration
Instead of passing all arguments via the command line, the CLI also supports reading TypeDoc configuration from json files.
typedoc.json
When running typedoc from the CLI, you can define any option except the entry files in a json file named typedoc.json
.
{
"entryPoints": ["src/index.ts"],
"out": "docs"
}
tsconfig.json
TypeDoc options can be defined withing an existing tsconfig.json
file. Use a typedocOptions
section to define
options as a json model.
{
"compilerOptions": {
"normalTypeScriptOptions": "here"
},
"typedocOptions": {
"entryPoints": ["src/index.ts"],
"out": "docs"
}
}
Node module
If you would like dynamic configuration or would like to run typedoc without using the CLI, import the node module and build the documentation yourself.
const TypeDoc = require("typedoc");
async function main() {
const app = new TypeDoc.Application();
// If you want TypeDoc to load tsconfig.json / typedoc.json files
app.options.addReader(new TypeDoc.TSConfigReader());
app.options.addReader(new TypeDoc.TypeDocReader());
app.bootstrap({
// typedoc options here
entryPoints: ["src/index.ts"],
});
const project = app.convert();
if (project) {
// Project may not have converted correctly
const outputDir = "docs";
// Rendered docs
await app.generateDocs(project, outputDir);
// Alternatively generate JSON output
await app.generateJson(project, outputDir + "/documentation.json");
}
}
main().catch(console.error);
Third-Party Tools
Gulp
- Name
- gulp-typedoc
- Website
- https://www.npmjs.org/package/gulp-typedoc/
- Author
- Rogier Schouten
You can install the plugin with the following command:
$ npm install --save-dev gulp-typedoc
Update the following snippet with your configuration and add it to your gulpfile.js
file:
var typedoc = require("gulp-typedoc");
gulp.task("typedoc", function () {
return gulp.src(["src/**/*.ts"]).pipe(
typedoc({
out: "docs/",
name: "My project title",
})
);
});