documentation
包,但无法弄清楚如何让它记录类属性(不是通过 getter 和 setter 定义的)。
如下仅生成 SomeClass 的类文档,但省略了 someProperty 文档。
/**
* SomeClass is an example class for my question.
* @class
* @constructor
* @public
*/
class SomeClass {
constructor () {
this.someProperty = true // how do I document this?
}
/**
* someProperty is an example property that is set to `true`
* @property {boolean} someProperty
* @public
*/
}
旁白:jsdoc 类上的
@constructor
是一个 documentation
的东西。
将
someProperty
的 JSDoc 移至首次定义它的构造函数中:
/**
* SomeClass is an example class for my question.
* @class
* @constructor
* @public
*/
class SomeClass {
constructor () {
/**
* someProperty is an example property that is set to `true`
* @type {boolean}
* @public
*/
this.someProperty = true
}
}
documentation
包 使用不涉及将 JSDocs 内联到构造函数中的方法来完成它。
这是在类文档中声明它们的另一种方法:
/**
* Class definition
* @property {type} propName - property description
* ...
*/
class ClassName {
constructor () {...}
...
}
您可以在类中声明属性,并使用@type为其声明类型。在 VSCode 1.70.2 中使用纯 ECMAScript 模块工作。
class Foo {
/**
* Some bary data
* @type { BarClass }
*/
bar;
}
let f = new Foo();
f.bar; // Intellisense can tell you type and purpose