JSDoc @augments @typedef not working as expected | WebStorm
According to the JSDoc documentation (http://usejsdoc.org/tags-augments.html), I should be able to define a type (http://usejsdoc.org/tags-augments.html) and have it extended / augment another defined type. In my case, I am adding additional (optional) properties to the instance of an "Error" object and passing that "extended" object through to another function. Here is my @typedef definition, as well as the function handler that is using it:
/**
* @typedef {Object} ExtendedError
* @augments {isntanceof Error}
* @param {String} [userMessage]
*/
/**
*
* @param {ExtendedError} err - http://expressjs.com/en/guide/error-handling.html
* @param {Request} req - http://expressjs.com/en/4x/api.html#req
* @param {Response} res - http://expressjs.com/en/4x/api.html#res
* @param {Function} next - https://expressjs.com/en/guide/using-middleware.html
* @returns {undefined}
*/
module.exports = function errorHandler(err, req, res, next) {
// Every property of the Error object is undefined here, such as: err.stack, err.code, err.status
};
If you need any further information, please let me know and I will do my best to provide it.
请先登录再写评论。
You can try using
instead. See https://stackoverflow.com/questions/36737921/how-to-extend-a-typedef-parameter-in-jsdoc, https://github.com/jsdoc3/jsdoc/issues/1199
Thank you! I will try this out and see if it works. I appreciate the reply!
Sincerely,
Shane Tarleton
I have another question about @extends, so will post it here rather than in separate issue.


I want to extend native Set class. Without any docs for it, my class is considered incompatible with other built-ins, like this:
So I added "@extends Set" to jsdoc. And now I have this warning:
And plus, previous warning (in `Array.from`) is still there. So adding this jsdoc did nothing for me.
I'm pretty new to jsdoc, so I don't know – is it normal? I thought, using "@extends" should mean that everything from extended class is inherited and available. But looks like it's not. Am I doing smth wrong?
>So I added "@extends Set" to jsdoc. And now I have this warning:
can't reproduce with @extends, only with @implements... You can turn JavaScript | General | Closure compiler syntax inspection off to get rid of the issue
>And plus, previous warning (in `Array.from`) is still there. So adding this jsdoc did nothing for me.
Set is not explicitly declared as a subtype of these interfaces, and structural subtyping doesn't work in JSDoc (https://youtrack.jetbrains.com/issue/WEB-41321)
> You can turn JavaScript | General | Closure compiler syntax inspection off to get rid of the issue

This helped, thank you.
> structural subtyping doesn't work in JSDoc
Ok. Sad, but at least, it's possible to use workaround: