配置 Visual Studio Code 建议 [英] Configure Visual Studio Code suggestions

查看:31
本文介绍了配置 Visual Studio Code 建议的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

识别哪个 Visual Studio Code 设置正在生成/允许弹出各种建议(以便可以将其关闭)的最佳方法是什么?特别是我想从展示中消除这三个.

What's the best way to identify which Visual Studio Code setting is generating / allowing various suggestions to pop up (so it can be turned off)? In particular I'd like to eliminate these three from ever showing.

推荐答案

这些建议是标准库中的类型.为 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

这篇关于配置 Visual Studio Code 建议的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆