在 JSDoc 中定义内联匿名函数的参数

问题描述 投票:0回答:2

如果我将函数定义为变量对象,那么 PhpStorm 将显示

item
参数的自动完成。

        /**
         * @param {Rules.FolderGroupItem} item
         **/
        var forEach = function(item) {
            if(item.type == 'label')
            {
                str += this.renderLabel(item.paramType);
            }
            if(item.type == 'input')
            {
                str += this.renderInput(item.paramType);
            }
        };
        _.each(items,forEach,this);

如果我为

_.each()
函数编写相同的内容作为内联参数。然后就不行了。

        _.each(items,forEach,
            /**
             * @param {Rules.FolderGroupItem} item
             **/
            function(item) 
        {
            if(item.type == 'label')
            {
                str += this.renderLabel(item.paramType);
            }
            if(item.type == 'input')
            {
                str += this.renderInput(item.paramType);
            }
        });
javascript annotations phpstorm jsdoc
2个回答
12
投票

我找到了答案。在这里。

    _.each(items,forEach,function(/*Rules.FolderGroupItem*/item) 
    {
        if(item.type == 'label')
        {
            str += this.renderLabel(item.paramType);
        }
        if(item.type == 'input')
        {
            str += this.renderInput(item.paramType);
        }
    });

0
投票

我必须在评论开头写一个double

**
才能工作。 使用 PhpStorm 2022.3.2,构建 #PS-223.8617.59。
谢谢你@Reactgular的提示。

/**
 *
 * @type {Array<Assignment>}
 */
let arr = [];
_.each(arr, /**Assignment*/ itemInArray => {

});

这样代码完成也可以正常工作:

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