首页 > 解决方案 > 如何使用 Js 文档记录 curried 函数

问题描述

我试图使用 Js docs 来生成我的项目的静态文档,但是当我尝试运行 js doc 命令时出现很多解析错误,仅发生在我有 curried 函数的地方,我的代码正常工作,错误仅在 js 上docs,它是一个库错误还是我做错了什么?

/**Responsible for fetch the data that will be loaded in the graph within the dialog
 *
 * @param {function} dispatch redux dispatch function
 * @param {String} timeMode time mode used on metric page Example: 'Mensal'
 * @param {String} dialogType type of the dialog used to request de correct data and render the body Example: 'WARN_NETWORK_DRIVE'
 * @returns {(timeMode: String) => (dialogType: String) => Promise<void>}
 */
export const fetchGraphicData = dispatch => timeMode => async dialogType => {...function logic }

错误: 在此处输入图像描述

标签: javascriptjsdoc

解决方案


我认为您不能从接收它的函数中记录返回函数的参数。您必须拆分文档,例如:

/**
 * @param {String} dialogType type of the dialog used to request de correct data and render the body Example: 'WARN_NETWORK_DRIVE'
 */
const dialogFn = async dialogType => { };

/**
 * @param {String} timeMode time mode used on metric page Example: 'Mensal'
 */
const timeModeFn = timeMode => dialogFn;

/**
 * Responsible for fetch the data that will be loaded in the graph within the dialog
 *
 * @param {function} dispatch redux dispatch function
 * @returns {timeModeFn} timeModeFn
 */
export const fetchGraphicData = dispatch => timeModeFn;

推荐阅读