How to annotate with JSDoc
comment a function
that accepts and returns object of the same type ? 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
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
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.