如何在 VSCode 中禁用 TypeScript 警告?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/42632215/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 07:36:44  来源:igfitidea点击:

How to disable TypeScript warnings in VSCode?

typescriptvisual-studio-codevscode-settings

提问by stefan2410

I don't use TypeScript for the time being. Only ES6 with babel.
I don't have installed TypeScript in node_modules.

我暂时不使用 TypeScript。只有带有 babel 的 ES6。
我没有在node_modules 中安装 TypeScript 。

I get a specific warning from VSCode every time I open a workspace.

每次打开工作区时,都会收到来自 VSCode 的特定警告。

\node_modules\typescript\libdoesn't point to a valid tsserverinstall. Falling back to bundled TypeScript version.

\node_modules\typescript\lib不指向有效的tsserver安装。回退到捆绑的 TypeScript 版本。

How can I get rid of such warnings? Or should I change editor in order to feel calm?

我怎样才能摆脱这样的警告?还是我应该换个编辑器才能平静下来?

回答by Johannes Rieken

TypeScript and JavaScript validation can be turned off in VS Code with these two settings:

可以使用以下两个设置在 VS Code 中关闭 TypeScript 和 JavaScript 验证:

"typescript.validate.enable": false,
"javascript.validate.enable": false,

Happy Coding

快乐编码

回答by marcdahan

  1. open the command palette : CTRL+ SHIFT+ P

  2. open the file settings.json :

  1. 打开命令调色板:CTRL+ SHIFT+P

  2. 打开文件 settings.json :

enter image description here

在此处输入图片说明

  1. add these 2 lines of code:

    "typescript.validate.enable": false,
    "javascript.validate.enable": false,
    
  1. 添加以下两行代码:

    "typescript.validate.enable": false,
    "javascript.validate.enable": false,
    

回答by Bernard Leech

I was having a similar problem. I had an incorrect setting for typescript.tsdkin my user settings:

我遇到了类似的问题。我的typescript.tsdk用户设置中有一个不正确的设置:

"typescript.tsdk": null

To fix it, you can either set the location to a valid location:

要修复它,您可以将位置设置为有效位置:

"typescript.tsdk": "/usr/local/lib/node_modules/typescript/lib",

or just remove the line from your settings if are not using Typescript.

或者如果不使用 Typescript,则从您的设置中删除该行。

If you need more detail, I found the VSCode docsto be very concise and easy to understand.

如果您需要更多详细信息,我发现VSCode 文档非常简洁且易于理解。

回答by K F

If you want to modify a setting, open the settings option (there is a new settings editor by the time I am writing this) and search for the setting you want to modify. I was attempting to change the typescript validation, but I wasn't allowed as the document was read only. If you hover over the setting, you get a pen on the left of the setting. If you right click on the pen, it will give you the option of true or false, as for my case I was targeting "typescript.validate.enable". I changed it to false, which in turn, VS code copied the code into the right of the screen with the new value. In short, the left is the settings.json file. On the right, you have the user-settings.json. You are only allowed to modify the user settings and the user setting can override any settings in the main settings.jsonfile. -Kf

如果要修改设置,请打开设置选项(在我撰写本文时有一个新的设置编辑器)并搜索要修改的设置。我试图更改打字稿验证,但由于该文档是只读的,因此不允许我这样做。如果将鼠标悬停在该设置上,则会在该设置的左侧看到一支笔。如果您右键单击笔,它将为您提供 true 或 false 选项,就我的情况而言,我的目标是"typescript.validate.enable"。我将其更改为 false,这反过来,VS code 将代码复制到屏幕右侧并带有新值。总之,左边是settings.json文件。在右侧,您有 user-settings.json。您只能修改用户设置,用户设置可以覆盖主settings.json文件中的任何设置。-Kf

enter image description here

在此处输入图片说明