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 )
{});
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 )
{});
Share
Improve this question
edited Jun 19, 2013 at 12:39
Discipol
asked May 2, 2013 at 23:03
DiscipolDiscipol
3,1574 gold badges24 silver badges43 bronze badges
3 Answers
Reset to default 3You can use plex "typedef" and "property" tags. Documented in: http://usejsdoc/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./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/tags-param.html
This is vague question, so here's my guess:
socket.on( "data",
/**
* @param request {Object}
* @param request.code {Number}
* @param request.id {Number}
* @param request.sr {String}
*/
function( request )
typeof request.id == 'number';
console.log(request.sr); // will print out the string
{});
The ment just describes which data / keys should be expected in the request object.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745138688a4613327.html
评论列表(0条)