how to (force) document a function type in javascript?

I'm running webstorm 6.02.

I think what I'm asking for is support for closure's @function or @type {function(foo,bar,baz)}

My question is, given something like:

var myfunc =  someMethodThatReturnsAFunction();


var o = { myfunc: someMethodThatReturnsAFunction() };

How can I document (for code assist in WS) myfunc? For example, if someMethodThatReturnsAFunction() returns a function that takes a single string parameter I'd lke to annotate myfunc to explicitly express that it is a of type {function(string)}

This is a powerful feature of javascript, but I can't figure out how to get accurate code assist with a code construct like the above?

Comment actions Permalink

Hi Shawn,
WebStorm supports such declarations, i.e.

/** @type {function(string)} */
var myfunc = someMethodReturningAFunction();


will warn that 1 is not assignable to string. What code assist do you expect to get?


Comment actions Permalink

I'm hoping for method documentation (CTRL+Q default) to work, and also parameter info (CTRL+P) like any other 'normal' js function. It doesn't appear to support either using the syntax above or any combination of things that work on regular functions.

I have other useful jsdoc comments uisng typical tags (@param, @returns, @example etc.) on these methods and would love to see the same rich information that I could for any other directly defined js function.


Please sign in to leave a comment.