typedoc-plugin-typescript-declaration
This is a Typedoc plugin that renders a TypeScript declaration file.
Installation
npm install typedoc typedoc-plugin-typescript-declaration --save-dev
Usage
Used as a plugin with Typedoc:
node_modules/.bin/typedoc --out docs --declarationFile docs/index.d.ts
node_modules/.bin/typedoc --declarationFile docs/index.d.ts
node_modules/.bin/typedoc --declarationFile docs/index.d.ts src/index.ts
node_modules/.bin/typedoc --out docs/v1.0 --declarationFile docs/v1.0/index.d.ts --maxVersion 1.0
node_modules/.bin/typedoc --out docs/v2.0 --declarationFile docs/v2.0/index.d.ts --maxVersion 2.0
Used as a stand alone cli (works with the same options above):
npx typedoc-plugin-typescript-declaration --declarationFile index.d.ts
npm install --global typedoc-plugin-typescript-declaration
node_modules/.bin/typedoc-declare --declarationFile index.d.ts --maxVersion 2.0
typedoc-declare --declarationFile index.d.ts --maxVersion 2.0
Why?
Reasons for using this plugin:
- You publish and maintain TypeScript definitions
- You have
@internal
or @hidden
types in your documentation that you would like reflected in your type definitions - You would like to publish multiple versions of your type definitions from a single source of truth
Publish multiple versions
You can target multiple versions of the type definitions by using the @since <version>
tag and suppliying a maximum version number with --maxVersion <version>
. Any definitions tagged with a @since
version greater than the --maxVersion
will be filtered out.
Example
Sample file:
export class MyClass {
originalFunction() {}
newFunction() {}
newerFunction() {}
}
Command:
node_modules/.bin/typedoc --declarationFile docs/v1.0/index.d.ts --maxVersion 1.0
node_modules/.bin/typedoc --declarationFile docs/v2.0/index.d.ts --maxVersion 2.0
Inlining keyof
types
You can use this plugin to @inline keyof
types directly into a union to produce a more concise document and .d.ts
file.
In addition to comments for each of the keys will also be documented as part of the @inline
type.
Example
Sample file:
type SwitchState = keyof {
on: string,
off: string,
unknown: string,
};
Produces the following (with --maxVersion 1.0
):
type SwitchState = "on" | "off";