使用 TypeDoc 记录外部类型
Documenting external types with TypeDoc
我有两个文件,文件 A 和文件 B。文件 A 使用文件 B 中的 class。我的目标是引用文件 B 中使用的 class 的 TypeDoc 输出文件 A 的 TypeDoc 输出。我似乎做不到。
我知道您可以使用带双括号的 TypeDoc 引用包含在同一文件中的符号,例如 [[Foo]]
,但这不适用于像这样的外部类型。
/** Trying to reference [[FileB.InnerClass]] like this doesn't work. */
// This here is what I want to include
export type InnerClass = FileB.InnerClass;
// More code...
这可以实现吗?
是的,有可能。
- 更正评论。
- 您不必输入文件名,但您必须使用
import
从文件导入对象
import { InnerClass } from './FileB';
/**
* See the [[InnerClass]] for more details.
*/
export type innerClass = InnerClass;
- 要生成文档,运行以下命令。
当 typedef
是全局时使用此命令:
typedoc --out ./docs --target ES6 ./src/
或者在本地时是这样的:
npx typedoc --out ./docs --target ES6 ./src/
./docs
是生成文档的文件夹。
./src/
是您的代码所在的文件夹。
--target ES6
版本 JavaScript.
如果只想显示 类 而没有不同的模块,请使用此标志 --mode file
:
npx typedoc --out ./docs --mode file --target ES6 ./src/
有关详细信息,请参阅 documentation。
我有两个文件,文件 A 和文件 B。文件 A 使用文件 B 中的 class。我的目标是引用文件 B 中使用的 class 的 TypeDoc 输出文件 A 的 TypeDoc 输出。我似乎做不到。
我知道您可以使用带双括号的 TypeDoc 引用包含在同一文件中的符号,例如 [[Foo]]
,但这不适用于像这样的外部类型。
/** Trying to reference [[FileB.InnerClass]] like this doesn't work. */
// This here is what I want to include
export type InnerClass = FileB.InnerClass;
// More code...
这可以实现吗?
是的,有可能。
- 更正评论。
- 您不必输入文件名,但您必须使用
import
从文件导入对象
import { InnerClass } from './FileB';
/**
* See the [[InnerClass]] for more details.
*/
export type innerClass = InnerClass;
- 要生成文档,运行以下命令。
当 typedef
是全局时使用此命令:
typedoc --out ./docs --target ES6 ./src/
或者在本地时是这样的:
npx typedoc --out ./docs --target ES6 ./src/
./docs
是生成文档的文件夹。./src/
是您的代码所在的文件夹。--target ES6
版本 JavaScript.
如果只想显示 类 而没有不同的模块,请使用此标志 --mode file
:
npx typedoc --out ./docs --mode file --target ES6 ./src/
有关详细信息,请参阅 documentation。