【问题标题】:Annotate param in anonymous function在匿名函数中注释参数
【发布时间】:2017-06-16 12:13:31
【问题描述】:

我正在努力寻找一种方法来注释胖箭头函数中的参数。在这里,让我给你看例子:

angular.forEach(someIterable, (item, key) => {
   // here I need item to be annotated
})

所以我尝试了:

/**
 * @param {MyType} item
 */
angular.forEach(someIterable, (item, key) => {
   // here I need item to be annotated
})

甚至:

angular.forEach(someIterable, (/** @type {MyType} */ item, key) => {
   // here I need item to be annotated
})

但是不,它不起作用。当然,我可以在箭头函数中做类似他的事情,但我不想这样做。

/** @type {MyType} */
let annotatedItem = item;

有没有办法做到这一点?我可以将箭头函数提取到单独的变量中,然后将其作为第二个参数传递给 forEach,但我也不想这样做,因为它会使我的代码的可读性大大降低。

【问题讨论】:

  • “但不,它不起作用。” ?什么?怎么不?
  • IDE 看不懂(Intelijj IDEA)
  • 我明白了...最近的版本(例如 2016.2)应该为 ECMA6 jetbrains.com/help/idea/2016.2/… 做这个
  • 在 IDEA 2017.1.3 中不工作

标签: javascript ecmascript-6 jsdoc


【解决方案1】:
angular.forEach(someIterable,
/**
 * @param {MyType} item
 */
(item, key) => {
   // here I need item to be annotated
})

是的,评论的地方很丑

【讨论】:

    猜你喜欢
    • 2021-12-04
    • 2010-09-27
    • 2021-02-19
    • 1970-01-01
    • 2020-01-03
    • 2011-03-02
    • 2019-02-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多