首页 > 解决方案 > 有没有办法在 TypeScript 函数文档中引用参数?

问题描述

我试图在这样的函数描述中引用参数:

/**
 * Deletes the Travel Cost with the given {@param id}
 * @param id the id of the travel cost to be deleted
 */
deleteTravelCost(id: number): Observable<{}> { [...] }

但它似乎不适用于{@param id}. 调用函数时的结果如下:

(method) TravelCostsService.deleteTravelCost(id: number): Observable<{}>

Deletes the Travel Cost with the given {@param id}

@param id — the id of the travel cost to be deleted

我希望在引用参数的文档中有一个可点击的元素(在函数的一般描述中,而不是在实际参数描述中)。是否有正确的方法来引用描述中的参数甚至函数的返回?(我正在使用 Visual Studio Code)。

标签: typescript

解决方案


有没有办法正确引用参数

您不能交叉引用参数:https ://github.com/jsdoc/jsdoc/issues/1145#issue-126426000

返回描述中的函数

同样,您不能引用它。但是你可以用返回来记录它,例如:

/**
 * Deletes the Travel Cost with the given 
 * @param id the id of the travel cost to be deleted
 * @returns the result
 */
function deleteTravelCost(id: number): number {
  return id;
}

推荐阅读