如何用JSDoc
注释接受和返回相同 类型对象的function
?类似于以下内容:
/**
* Does some work and returns same type
* @param {T extends Object} src Source object
* @returns {T} object of the **same** type
*/
function chainFoo(src) {
// do some work
return Object.assing({}, src); // just as example
}
有可能吗?
答案 0 :(得分:1)
解决方案是指定@template T
所以看起来像这样:
/**
* Does some work and returns same type
* @template T
* @param {T} src Source object
* @returns {T} object of the **same** type
*/
function chainFoo(src) {
// do some work
return Object.assing({}, src); // just as example
}