简体   繁体   English

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

[英]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.

相关问题 通过 function 作为参数应该使用来自同一调用的另一个参数 - Passed function as param should use another param from the same call Angular,将泛型类型传递给另一个函数。 如何输入参数? - Angular, pass generic type into another function. How to typed param? 深度合并通用 function 返回类型从不 - Deep Merge generic function returns type never 如何在Flow中使用相同泛型类型的值来检查泛型函数 - How to typecheck a generic function using a value of that same generic type in Flow 如何确保类型检查 function 返回相同 arguments 的相同引用 - How to ensure type check a function returns the same reference for same arguments 如何使用Flow泛型使用相同类型的参数制作泛型函数 - How to make a generic function with the arguments of the same type using Flow generics 如何在Facebook Flow中的函数内部使用通用类型注释 - How to use a generic type annotation inside a function in Facebook Flow 接受通用参数并返回通用值的函数 - Function that takes generic arguments and returns generic value 如何将相同的 function 用于不同类型的输入? - how to use same function for different type of input? 是否可以根据传递给 function 的另一个参数对参数进行类型推断? - Is it possible to have type inference for a param based on the other param passed to a function?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM