JSDoc Typescript声明:如何隐藏“私有”方法

问题描述 投票:1回答:1

假设我有一个JavaScript类

/**
 * @element my-element
 */
export class MyElement extends HTMLElement {
  publicMethod() {}
  /** @private */
  privateMethod() {}
}

customElements.define('my-element', MyElement);

以及使用declarationallowJs生成的声明文件:

export class MyElement extends HTMLElement {
  publicMethod(): void;
  /** @private */
  privateMethod(): void
}

我也是,在构建后脚本中,将其连接到声明文件:

declare global { interface HTMLElementTagNameMap { 'my-element': MyElement; } }

在打字稿文件中使用此元素时,我可以自动完成方式访问privateMethod

import 'my-element'
const me = document.createElement("my-element")
me.// autocompletes `privateMethod`

如何指示tsc将用@private JSDoc标记注释的任何方法,字段或属性标记为私有?

javascript typescript jsdoc
1个回答
0
投票

您需要对要从文档中排除的那些方法和类使用@ignore批注。

@ ignore标记指示代码中的符号永远不会出现在文档中。

/**
 * @class
 * @ignore
 */
function Jacket() {
    /** The jacket's color. */
    this.color = null;
}

/**
 * @namespace
 * @ignore
 */
var Clothes = {
    /**
     * @class
     * @ignore
     */
    Jacket: function() {
        /** The jacket's color. */
        this.color = null;
    }
};

此处有更多信息:https://jsdoc.app/tags-ignore.html

© www.soinside.com 2019 - 2024. All rights reserved.