如何使用 JSDoc
注释一个接受并返回相同类型对象的函数
?类似于以下内容:
/**
* 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
}
这可能吗?
最佳答案
解决方案是指定@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
}
关于javascript - 在函数的@param 和@returns 中使用相同的泛型类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51771369/