【问题标题】:Deeper IntelliSense/Helptext in VSCode for Javascript/Typescript using node.js使用 node.js 在 VSCode 中为 Javascript/Typescript 提供更深入的 IntelliSense/Helptext
【发布时间】:2021-09-19 04:56:35
【问题描述】:

我对编程非常陌生(特别是在 JS/TS 中),但目前我尝试使用 node.js 进行试验,但有一点我特别不理解 IntelliSense 或VSCode 中的“帮助文本”。

例如,我尝试使用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 等是什么意思?

【问题讨论】:

    标签: javascript node.js typescript visual-studio-code


    【解决方案1】:

    您无法真正更改智能感知工具提示,但您始终可以通过 command+click (mac) 或 ctrl+click (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;
    

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

    【讨论】:

      猜你喜欢
      • 2020-05-05
      • 1970-01-01
      • 2017-03-09
      • 2021-12-07
      • 2021-05-06
      • 2017-02-03
      • 2015-07-12
      • 2021-07-05
      • 2022-01-08
      相关资源
      最近更新 更多