简体   繁体   English

使用 node.js 在 VSCode 中为 Javascript/Typescript 提供更深入的智能感知/帮助文本

[英]Deeper IntelliSense/Helptext in VSCode for Javascript/Typescript using node.js

I'm very new to programming (in JS/TS specifically and as a whole) but at the moment I try to experiment with node.js and there is one thing in particular that I don't understand with the IntelliSense or the 'helptext' in VSCode.我对编程非常陌生(特别是在 JS/TS 中以及作为一个整体)但目前我尝试使用 node.js 并且有一件特别的事情我不理解 IntelliSense 或“帮助文本” ' 在 VSCode 中。

For example I try to use fs.open() and get the following help text:例如,我尝试使用fs.open()并获得以下帮助文本:

open(path: fs.PathLike, flags: fs.OpenMode, mode: fs.Mode | null | undefined, 
callback: (err: NodeJS.ErrnoException | null, fd: number) => void): void

A path to a file. If a URL is provided, it must use the file: protocol.

Asynchronous open(2) - open and possibly create a file.

Now, as a newbie, how do I know what the type fs.PathLike looks like or includes?现在,作为一个新手,我怎么知道fs.PathLike的类型是什么样的或包括什么? If I look this method up in the node.js documentation I now know that the type fs.PathLike includes <string> | <Buffer> | <URL>如果我在 node.js 文档中查找此方法,我现在知道fs.PathLike类型包含<string> | <Buffer> | <URL> <string> | <Buffer> | <URL> <string> | <Buffer> | <URL> . <string> | <Buffer> | <URL> Aha!啊哈! So it can be as simple as the path to the file as a string.所以它可以像文件的路径一样简单,就像一个字符串。

But is there any way to see these information directly in VSCode?但是有没有什么办法可以直接在VSCode中看到这些信息呢? What fs.PathLike or fs.OpenMode etc. means? fs.PathLikefs.OpenMode等是什么意思?

You can't really change the intellisense tooltips, but you can always command+click (mac) or ctrl+click (windows) on anything to drill into it.您无法真正更改智能感知工具提示,但您始终可以在任何内容上使用 command+click (mac) 或 ctrl+click (windows) 进行钻取。

In this case if you drilled into fs.open it should take you to these types:在这种情况下,如果您深入fs.open它应该fs.open您带到以下类型:

    /**
     * Asynchronous open(2) - open and possibly create a file.
     * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
     * @param mode A file mode. If a string is passed, it is parsed as an octal integer. If not supplied, defaults to `0o666`.
     */
    export function open(path: PathLike, flags: OpenMode, mode: Mode | undefined | null, callback: (err: NodeJS.ErrnoException | null, fd: number) => void): void;

If you then drill into PathLike you should be taken to this type:如果你然后钻入PathLike你应该被带到这种类型:

    /**
     * Valid types for path values in "fs".
     */
    export type PathLike = string | Buffer | URL;

In practice, some type can be very complex.在实践中,某些类型可能非常复杂。 So showing the names of higher complexity types can be a good thing.因此,显示更复杂类型的名称可能是一件好事。 But it can also makes things opaque.但它也可以使事情变得不透明。 Being able to explore these types can really help, but it will never completely replace looking at official documentation.能够探索这些类型确实很有帮助,但它永远不会完全取代查看官方文档。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM