jsdoc/jsdoc.github.io

Callback does not own return type

deadmann opened this issue · 3 comments

lot of time we use callback only to pass user some data, and then user process them async, but there are also times when we want user return some data, once they processed the data through their own way, that's when the return type in doc become important...

Like linq libraries, or my case, or etc...., so the intellisense can/will guide the user through introducing the return value, if the user missed it by mistake, something i did a lot.

I'm not sure I understand what you're asking for. JSDoc provides a way to document the values that are passed to a callback; see the @callback tag docs for details. However, I can't promise you that your IDE will understand this syntax.

No, i look for return value of that function... you should also tell the user what to return sometimes.

here an e.g. between the developer and client of the code:

Developer:

var App;
(function (App){
    var EventManager= (function () {
        function EventManager() {
        }
        
        EventManager.handleClick(userMethod){
            if(userMethod($event)){
                 //continue operation
            }
            else{
                 //cancel operation
            }
        }

    }());
    App.EventManager = EventManager;
})(App || App={});

User:

EventManager.handleClick(???);

Developer:

...
/**
*@param userMethod {Function}
*/
...

User:

EventManager.handleClick(function(???){
...
return ???
});

Developer:

/**
*@callback EventCallback
*@param $event {EventArgs}
*/

/**
*@param userMethod {EventCallback}
*/

User:

EventManager.handleClick(/**param $event {EventArgs} */function($event){
...
return ???
});

now you see? still return type is unspecified and user cannot understand if he need to return something or not and what kind of data it should be!