繁体   English   中英

在函数的@param和@returns中使用相同的泛型类型

[英]Use of same generic type in @param and @returns for a function

如何用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    
}

可能吗?

解决方案是指定@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    
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM