首页 > 解决方案 > 当不确定 JSdocs 时该放什么 @return

问题描述

您好,我有一个函数,它返回该函数内部函数的结果。所以我有点不确定在我的@return. 我正在进入 JSdocs,这是我偶然发现的一个问题。

这是代码:

/**
 * @param           {string} id
 * @param           {Array} data
 * @returns         ??
 * @description     Takes in an ID to find the processor it needs and the data it needs to pass to the processor.
 */

processData(id, data) {
    let res = Object.values(methods).find(entry => entry.id === id).dataProcessor;
    if (res !== undefined) return res(data);
    console.error(`There is no method that belongs to id:${id}`)
}

因为它返回res.data(data)您将在文档中的 @return 中放入的结果。

标签: javascriptjsdoc

解决方案


通常,在这种情况下,我会返回一个{Object}、 或 ALL {*},甚至是 ANY {?}

https://github.com/google/closure-compiler/wiki/Types-in-the-Closure-Type-System


推荐阅读