使用node.js的Javascript/Typescript的VSCode中的深层IntelliSense/Helpt



我对编程(特别是在JS/TS中,作为一个整体(非常陌生,但目前我试图尝试使用node.JS,有一件事我特别不理解VSCode中的IntelliSense或"helptext"。

例如,我尝试使用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.

现在,作为一个新手,我如何知道类型fs.PathLike是什么样子或包括什么?如果我在node.js文档中查找这个方法,我现在知道类型fs.PathLike包括<string> | <Buffer> | <URL>。啊哈!因此,它可以简单到将文件的路径作为字符串。

但是有没有办法直接在VSCode中看到这些信息?fs.PathLikefs.OpenMode等是什么意思?

您不能真正更改intellisense工具提示,但您可以在任何东西上命令+单击(mac(或ctrl+单击(windows(来深入其中。

在这种情况下,如果你深入了解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;

如果你钻入PathLike,你应该被带到这种类型:

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

在实践中,某些类型可能非常复杂。因此,显示复杂度较高的类型的名称可能是一件好事。但它也会使事情变得不透明。能够探索这些类型确实有帮助,但它永远不会完全取代查看官方文档。

最新更新