【问题标题】:JSDoc - how to document function's static variableJSDoc - 如何记录函数的静态变量
【发布时间】:2020-10-22 14:42:12
【问题描述】:

我如何正确地 JSDoc 下面的函数?

function foo() {
  foo.counter = 1 + (foo.counter || 0)
}

目前 TS 类型检查(在 vscode 中,使用 checkJs=true)抱怨: Property 'counter' does not exist on type '() => void'

【问题讨论】:

标签: javascript jsdoc


【解决方案1】:

您可以使用 JSDoc 记录静态成员。我会为此使用namepath,并使用一个额外的块:

function foo() {
}

/**
 * My static counter
 * @name foo.counter
 * @type {number}
 */
foo.counter = 0;

现在我的 IDE(VS 代码)能够将其视为属性并提取文档:

【讨论】:

    猜你喜欢
    • 2016-06-03
    • 2013-05-30
    • 1970-01-01
    • 1970-01-01
    • 2015-07-12
    • 1970-01-01
    • 2017-11-05
    • 2012-08-12
    • 1970-01-01
    相关资源
    最近更新 更多