Attaching Javascript documentation to VSCode

Hi, I’m using Visual Studio Code 1.61.2 to write javascript.
Let’s say i write something like this

function longest(list) {
  const lengths = list.map((str, index) => ({
    index,
    length: str.length
  }));

  console.dir(lengths);

  const i = lengths.reduce(
    (acc, obj) => (obj.length > acc ? obj.index : acc),
    -1
  );

  return list[i];
}

Using a Mac I can put the cursor over either console or dir and press Command and view the documentation in a popup.

This does not work on the .map method.
How do I configure VSCode so that I can see the method information for .map ?

I want it to link to an explanation as comprehensive as https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map

Thanks

Jon

Hi @jonbangbanggreenwood, the language service doesn’t know that your list parameter is supposed to be an array; it can infer the type to some extent if you add a default value (say), but to be explicit you can add JSDoc annotations:

/**
 * @param {string[]} list 
 * @returns {string}
 */
function longest (list) {
  // ...
}
1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.