Reputation: 699
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?
Upvotes: 2
Views: 1006
Reputation: 699
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
}
Upvotes: 7