A JSDoc plugin with an optional template which automatically adds JSDoc comments based on Typescript definitions.
Automatically adds JSDoc comments based on Typescript's types:
Adds @ctor, @callsignature, @ctorsignature, @generic tags.
Override @enum tag to change its kind as typedef.
Supports classes with multiple constructors using @ctor tag.
Supports interfaces call signatures and constructs signature @callsignature and @ctorsignature.
Automatically adds comments for anonymous types using @callback or @typedef tags.
Transforms interfaces with only call signatures in callbacks.
You can see some demos here:
First install the plugin as a dependency.
$ npm install ts2jsdoc
Then configure the plugin and the template using JSDoc's conf.json
:
{
"source": {
"includePattern": "(\\.d)?\\.ts$"
},
"plugins": [
"node_modules/ts2jsdoc/plugin.js"
],
"opts": {
"template": "node_modules/ts2jsdoc/template"
}
}
All Typescript's compiler options are available.
Plugin options are provided using JSDoc's config.json
:
"typescript": {
"target": "{es3|es5|es6|latest}",
"module": "{commonjs|amd|none}",
"codepage": "{number}",
"charset": "{string}",
"mapRoot": "{string}",
"sourceRoot": "{string}",
"allowNonTsExtensions": "{boolean}",
"declaration": "{boolean}",
"diagnostics": "{boolean}",
"emitBOM": "{boolean}",
"noEmitOnError": "{boolean}",
"noErrorTruncation": "{boolean}",
"noImplicitAny": "{boolean}",
"noLib": "{boolean}",
"noLibCheck": "{boolean}",
"noResolve": "{boolean}",
"preserveConstEnums": "{boolean}",
"removeComments": "{boolean}",
"suppressImplicitAnyIndexErrors": "{boolean}"
}
The template allows you to easily take advantage of the full plugin features. It supports generic annotations, call signatures, construct singatures and anonymous types and callbacks.
It's entirely based on Bootstrap so it's easily customizable using a simple Bootstrap theme.
Template options are provided using JSDoc's config.json
:
"templates": {
"systemName": "{string}",
"theme": "{path | default}",
"navType": "{vertical | inline}",
"inverseNav": "{boolean}",
"tableOfContents": "{boolean}",
"linenums": "{boolean}",
"collapseSymbols": "{boolean}",
"footer": "{string}",
"copyright": "{string}",
"analytics": "{string}",
"outputSourceFiles": "{boolean}",
"outputSourcePath": "{boolean}"
}
staticFiles
JSDoc option to add the theme in the template."inline"
. Otherwise set it to "vertical"
to make them regular stacked dropdowns.true
to use the inverse header.true
all of the symbols in the page will roll their contents up so that you just get a list of symbols that can be expanded and collapsed."analytics": "UA-XXXXX-XXX"
.ts2jsdoc can also be used as a standalone CLI tool to generate .js.doc files from Typescript files.
First install ts2jsdoc as a global pacakge.
$ npm install -g ts2jsdoc
Then you can use the plugin with the same options as tsc
.
$ ts2jsdoc --module commonjs --target es5 lib.d.ts
Any contribution is welcome !
First, clone the repository:
$ git clone https://gitub.com/spatools/ts2jsdoc.git
Then install dev dependencies:
$ npm install
Then project is using Grunt.js for test and build. To start a task type:
$ grunt <task>
.npmignore
issues.