javascript - How do I JSDoc @param in webstorm a callback handler's parameters? - Stack Overflow

I am trying to use JSDoc hinting on the parameter of a handler but it doesn't work. I have tried w

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
Add a ment  | 

3 Answers 3

Reset to default 3

You 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条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信