I am trying to use JSDoc hinting on the parameter of a handler but it doesn't work. I have tried with @type and @param and it does not work. The official JSDoc did not contain any helpful information regarding this problem.
This does not work:
socket.on( "data",
/**
* @param request {Object}
* @param request.code {Number}
* @param request.id {Number}
* @param request.sr {String}
*/
function( request )
{});
The @param tag provides the name, type, and description of a function parameter. The @param tag requires you to specify the name of the parameter you are documenting.
JSDoc comments are used for documentation lookup with Ctrl+Q in JavaScript and TypeScript, see JavaScript documentation look-up and TypeScript documentation look-up, as well as for type annotations and method return type hints in chained methods.
The param() method creates a serialized representation of an array or an object. The serialized values can be used in the URL query string when making an AJAX request.
You can use complex "typedef" and "property" tags. Documented in: http://usejsdoc.org/tags-typedef.html However, "~" char seems to prevent WebIde to link type annotations. (Just use plain typedef MyType annotation without tilde and it works)
BTW, for Google Closure way:
/** @typedef {{code: Number, id: Number, str: String}} **/
SocketRequest;
socket.on("data", handler);
/**
* @param {SocketRequest} req
*/
function handler(req) {
//req will be hinted here
}
This jsdoc annotation is especially for Google Closure, but can be used without Closure just for the sake of hinting. (should work since August 2012: http://blog.jetbrains.com/webide/2012/08/closure-syntax/)
I think you swapped the type and name of the objects, perhaps swapping them could help?
This is for jsdoc3, but I think it is the same:
http://usejsdoc.org/tags-param.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With