簡體   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