Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSDoc: arrow function params

I'm trying to document my code with JSDoc (EcmaScript 2015, WebStorm 12 Build 144.3357.8).

I have an arrow function which I want to document its parameters. This two examples work (I get auto-completion):

/** @param {Number} num1*/
var a = num1 => num1 * num1;
//------------------------------
/** @param {Number} num1*/
var a = num1 => {
    return num1 * num1;
};

But when I want to document an arrow function in forEach function, for example, the auto-completion isn't working (all of the below):

/** @param {Number} num1*/
[].forEach(num1 => {
    return num1 * num1;
});
//------------------------------
/** @param {Number} num1*/
[].forEach(num1 => num1 * num1);
//------------------------------
[].forEach(/** @param {Number} num1*/num1 => num1 * num1);
//------------------------------
[].forEach(/** @param {Number} num1*/num1 => {
    return num1 * num1;
});

Has anyone managed to get this work?

like image 695
Ziki Avatar asked Jan 31 '16 09:01

Ziki


People also ask

What is the JSDoc keyword to specify an argument to a function?

The @param tag provides the name, type, and description of a function parameter.

What is JSDoc comment?

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.

Can you use JSDoc with TypeScript?

You can use most JSDoc type syntax and any TypeScript syntax, from the most basic like string to the most advanced, like conditional types.

Is JSDoc useful?

Using TypeScript consistently offers a lot of benefits, especially for writing clean code to prevent unnecessary bugs and errors.


1 Answers

Starting from the next EAP build, WebStorm will understand this:

[].forEach(/**Number*/num1 => {
    return num1 * num1;
});

Please look at WEB-19280 for details.

like image 131
de1mar Avatar answered Sep 19 '22 18:09

de1mar