且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

配置 Visual Studio Code 建议

更新时间:2022-06-08 10:22:58

这些建议是标准库中的类型.为 VS Code 的 JavaScript 和 TypeScript 语言功能提供支持的 TypeScript 服务从 .d.ts 文件加载这些类型,以了解标准 JavaScript 库函数(例如 parseInt承诺.

Those suggestions are types from the standard library. The TypeScript service that powers VS Code's JavaScript and TypeScript language features loads these types from .d.ts files in order to understand the signatures of standard JavaScript library functions such as parseInt or Promise.

要找出类型的来源,请尝试使用工作区符号搜索 (cmdT):

To find out where a type is coming from, try using workspace symbol search (cmdT):

在这种情况下,这些类型来自 TypeScript 自动加载的标准 lib.d.ts 文件.TypeScript 还会自动为 DOM api 加载 d.ts 文件.

In this case, these types come from the standard lib.d.ts file that TypeScript loads automatically. TypeScript will also automatically load a d.ts file for the DOM api.

要禁用这些建议,请在项目的根目录下创建一个 jsconfig.json 内容:

To disable these suggestions, create a jsconfig.json at the root of your project with the contents:

{
    "compilerOptions": {
        "lib": []
    }
}

这告诉打字稿不要为核心库包含任何额外的打字文件.您还可以选择要包含的类型:

This tells typescript not to include any extra typings files for the core libraries. You can also select which typings you want to include:

{
    "compilerOptions": {
        "lib": [
            "es2015"
        ]
    }
}

请参阅文档以获取有效的列表lib 选项

See the documentation for a list of valid lib options

如果您发现此行为的任何错误或对如何改进有任何建议,请针对 VS Code 提出问题

If you notice any bugs with this behavior or have any suggestions on how this could be improved, please file an issue against VS Code

更新

要了解类型建议的来源,您也可以这样写:

To discover where a type suggestion is coming from, you may also be able to write:

 /**
  * @type {AsyncResultObjectCallback}
  */
 var placeholer; 

然后在placeholder上运行go to type definition.即使使用 "lib": [],您仍可能会看到来自 @types 文件或包含 d.ts 文件的节点包的建议

And then run go to type definition on placeholder. Even using "lib": [], you may still be seeing suggestions from @types files or node packages that include d.ts files