13

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?

Pang
  • 9,564
  • 146
  • 81
  • 122
Ziki
  • 1,390
  • 1
  • 13
  • 34

2 Answers2

13

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

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

Please look at WEB-19280 for details.

de1mar
  • 1,176
  • 10
  • 6
  • 3
    I came across this question when looking for vscode solution that's how it's done in vscode [].forEach(/** @param {Number} num1*/ num1 => { .... } – Samiullah Khan Jan 20 '20 at 06:56
4

You can use this format:

/**
 * @param {(prevState: ActionState) => ActionState} setActionState
 */
function f(setActionState) {
  // ...
}

Or:

/**
 * @param {function(prevState: ActionState): ActionState} setActionState
 */
function f(setActionState) {
  // ...
}
Mir-Ismaili
  • 13,974
  • 8
  • 82
  • 100