[英]Use of same generic type in @param and @returns for a function
How to annotate with JSDoc
comment a function
that accepts and returns object of the same type ? 如何用
JSDoc
注释注释一个接受并返回相同 类型对象的function
? Something like the following: 类似于以下内容:
/**
* 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
}
Is it possible? 可能吗?
The solution is to specify @template T 解决方案是指定@template T
So it looks like this: 所以看起来像这样:
/**
* 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
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.