Documentation Automation

Documentation can be generated usingTypeDoc. It is tool for TypeScript project's.

TypeDoc Installation

Global installation

npm install --global typedoc

Local installation (in your project's directory as usual)

npm install --save-dev typedoc

After installation you can run command:

typedoc

to see available TypeDoc and TypeScript options for generation documents .

Next create filetypedoc.jsonin project's root folder with some basic options:

{
  "mode": "modules",
  "out": "docs",
  "theme": "default",
  "ignoreCompilerErrors": "true",
  "experimentalDecorators": "true",
  "emitDecoratorMetadata": "true",
  "target": "ES5",
  "moduleResolution": "node",
  "preserveConstEnums": "true",
  "stripInternal": "true",
  "suppressExcessPropertyErrors": "true",
  "suppressImplicitAnyIndexErrors": "true",
  "module": "commonjs"
}

Here property"out"means that we want to create documentation folder with namedocs.

Next is to add this lines into project'spackage.jsonscriptssection:

Here:

  • "docs"

    • it is name of command to build documents

  • our TypeDoc options are in

    typedoc.json

    file

  • we are excluding testing

    **/*.spec.ts

    files

  • source files form which documentation must be generated are in project's folder

    /src/app/

The command to build documentation is:

After successful command execution there will be message in console:

where...is absolute path to documents folder and folder structure is:

Now you can open documents index.html file in browser.

Describing Models/Components/Services

Example of Model description:

Example of Component description:

Example of Service description:

Code comments

The documentation generator currently understands these javadoc tags:

All other tags will be rendered as definition lists, so they are not lost.

Comment to some variable:

Function comments:

Modules comments

Modules can be commented like any other elements in TypeScript. As modules can be defined in multiple files, TypeDoc selects the longest comment by default. One may override this behaviour with the special@preferredcomment tag.

HTML tags in comments

It is possible to use HTML tags in comments. For example:

Last updated