问题
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