How do I get my npm module's JSdoc documentation for functions to show up in users' VScode?

大城市里の小女人 提交于 2020-02-06 23:53:31

问题


I'm kinda new to VScode, and TypeScript. I'm trying to publish a tiny module with in-depth documentation to npm, and have users' VScode installations show beautiful type-directed instructions when consuming my efforts.

When I try typing console.assert in VScode, I get something like this:

Cool! That's what I want my users to see!

However, when I try importing my own module, I seem to get types … but hovering over a callsite, I only see:

A distinct lack of … any of the carefully-detailed writeup I've published in the source-code. 🤣

What is necessary of a JavaScript documentation-comment to convince VScode (and, hopefully, other editors) to display it inline? Perhaps-relatedly, why does VScode say "alias" instead of "function" or "method" for my function?


回答1:


To show the documentation of your method when hovering over it you have to wrap it in a JSDoc formated documentation comment. For example:

my_lib.ts:

/**
 * converts something to something
 * @param eldritch_horror This my argument
 * @returns the converted stuff.
 */
export function fromFakeUTF8String(eldritch_horror: string): string {
    return 'hello world';
}

Now when your users import it and hover over the method call they will get the following result:



来源:https://stackoverflow.com/questions/57635453/how-do-i-get-my-npm-modules-jsdoc-documentation-for-functions-to-show-up-in-use

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!