JSDOC-用于多个声明的类型,一个接一个地

发布于 2025-02-06 08:03:07 字数 1788 浏览 0 评论 0原文

我目前正在使用此问题:

    /** @type {TagsLevel} */
    export let list;
    /** @type {string} */
    export let tagListName;
    
    /** @type {string | null} */
    let srcTag = null;
    /** @type {number | null} */
    let srcTagNum = null;
    /** @type {number | null} */
    let srcLevelNum = null;

还不清楚。

我希望我可以这样使用:

    /** @type {TagsLevel} */
    /** @type {string} */
    export let list;
    export let tagListName;
    
    /** @type {string | null} */
    /** @type {number | null} */
    /** @type {number | null} */
    let srcTag = null;
    let srcTagNum = null;
    let srcLevelNum = null;

这应该与以前的代码相同。

是否有JSDOC语法可以实现此类内容?

,如果没有,我想知道在哪里提出支持这种情况的建议。

为什么?

我遵循函数的语法 - @param。它不是完全相同的,但是非常相似:

// Parameters may be declared in a variety of syntactic forms
/**
 * @param {string}  p1 - A string param.
 * @param {string=} p2 - An optional param (Google Closure syntax)
 * @param {string} [p3] - Another optional param (JSDoc syntax).
 * @param {string} [p4="test"] - An optional param with a default value
 * @returns {string} This is the result
 */
function stringsStringStrings(p1, p2, p3, p4) {
  // TODO
}

替代方案 - 这是:


    /** @type {TagsLevel} */ export let list;
    /** @type {string} */    export let tagListName;
    
    /** @type {string | null} */ let srcTag = null;
    /** @type {number | null} */ let srcTagNum = null;
    /** @type {number | null} */ let srcLevelNum  = null;

但这也不是很清楚,并且使线路很长。

I am currently using this:

    /** @type {TagsLevel} */
    export let list;
    /** @type {string} */
    export let tagListName;
    
    /** @type {string | null} */
    let srcTag = null;
    /** @type {number | null} */
    let srcTagNum = null;
    /** @type {number | null} */
    let srcLevelNum = null;

It's not very clear.

I wish I could use it that way:

    /** @type {TagsLevel} */
    /** @type {string} */
    export let list;
    export let tagListName;
    
    /** @type {string | null} */
    /** @type {number | null} */
    /** @type {number | null} */
    let srcTag = null;
    let srcTagNum = null;
    let srcLevelNum = null;

This should work identically to the previous code.

Is there a JSDoc syntax that enables something like this?

If not, I would like to know where to make the suggestion that support for such a case be introduced.

WHY THIS?

I am following the syntax of the function - @param. It's not identical, but it's very similar:

// Parameters may be declared in a variety of syntactic forms
/**
 * @param {string}  p1 - A string param.
 * @param {string=} p2 - An optional param (Google Closure syntax)
 * @param {string} [p3] - Another optional param (JSDoc syntax).
 * @param {string} [p4="test"] - An optional param with a default value
 * @returns {string} This is the result
 */
function stringsStringStrings(p1, p2, p3, p4) {
  // TODO
}

The alternative - this:


    /** @type {TagsLevel} */ export let list;
    /** @type {string} */    export let tagListName;
    
    /** @type {string | null} */ let srcTag = null;
    /** @type {number | null} */ let srcTagNum = null;
    /** @type {number | null} */ let srcLevelNum  = null;

But it's not very clear either, and it makes the line very long.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文