typescript 从 VS Code 中的 JS 文件中删除 [ts] 错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/51069070/
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
Removing [ts] errors from JS files In VS Code
提问by Nathan Thibert
I get these TypeScript errors VS Code while I'm working in JS files. Is there anything I can do to disable this? I have put this in my settings and did not solve the issue:
在处理 JS 文件时,我收到了这些 TypeScript 错误 VS Code。我能做些什么来禁用它吗?我已经把它放在我的设置中,但没有解决问题:
"typescript.validate.enable": false
The error can been seen here
错误可以在这里看到
采纳答案by Kirk Larkin
There's a GitHub issuethat discusses the [ts]
token from the errors in a bit more detail. The most relevant comment to this discussion is:
有一个GitHub 问题[ts]
更详细地 讨论了错误中的令牌。与本次讨论最相关的评论是:
Yes. The TypeScript extension powers our javascript intellisense which is why you see
[TS]
in your js file. That only indicates what extension is providing that error.
是的。TypeScript 扩展支持我们的 javascript 智能感知,这就是您
[TS]
在 js 文件中看到的原因。这仅表明提供该错误的扩展名。
You can disable this validation itself by adding the following to an appropriate settings.json
file:
您可以通过将以下内容添加到适当的settings.json
文件来禁用此验证本身:
"javascript.validate.enable": false
The docsdiscusses this option a little bit further:
该文档讨论了这个选项远一点位:
With
javascript.validate.enable: false
, you disable all built-in syntax checking. If you do this, we recommend that you use a linter like ESLintto validate your source code.
使用
javascript.validate.enable: false
,您可以禁用所有内置语法检查。如果您这样做,我们建议您使用像ESLint这样的linter来验证您的源代码。
As noted above, this disables allbuilt-in syntax checking. Although the suggestion is to use something like ESLintinstead, there might be another option if you're specifically concerned about the import
/export
errors. You can add a jsconfig.json
file to your project with the following content:
如上所述,这会禁用所有内置语法检查。尽管建议改用ESLint 之类的东西,但如果您特别关注import
/export
错误,可能还有另一种选择。您可以将包含jsconfig.json
以下内容的文件添加到您的项目中:
{
"compilerOptions": {
"module": "es2015"
}
}
This instructs VS Code to use the es2015 module syntax (import
/export
), which appears to make it happier.
这指示 VS Code 使用 es2015 模块语法(import
/ export
),这似乎使它更快乐。
回答by BenE
回答by Ebuall
Make sure javascript.implicitProjectConfig.checkJs
is false VSCode settings.
确保javascript.implicitProjectConfig.checkJs
是错误的 VSCode 设置。
回答by james
On visual studio code File > Preferences > Settings Go to Extensions->TypeScript-> Javascript>Validate make sure Enable/disable JavaScript validatio
在 Visual Studio 代码 File > Preferences > Settings Go to Extensions->TypeScript-> Javascript>Validate 确保启用/禁用 JavaScript 验证
回答by Avinash
Open settings in your VSC.
To open your user and workspace settings, use the following VS Code menu command:
在 VSC 中打开设置。
要打开您的用户和工作区设置,请使用以下 VS Code 菜单命令:
- On Windows/Linux- File > Preferences > Settings
On macOS- Code > Preferences > Settings
Check iftslint.jsEnable
is set tofalse
// Control whether tslint is enabled for JavaScript files or not.
"tslint.jsEnable": false,
- 在Windows/Linux 上- 文件 > 首选项 > 设置
在macOS 上- Code > Preferences > Settings
检查是否tslint.jsEnable
设置为false
// Control whether tslint is enabled for JavaScript files or not.
"tslint.jsEnable": false,
Set it to falsein workspace settingssection
在工作区设置部分将其设置为false
From the documentation:
tslint.enable- enable/disable tslint.
tslint.jsEnable- enable/disable tslint for .js
files, default is false.
来自文档:
tslint.enable- 启用/禁用 tslint。
tslint.jsEnable- 启用/禁用.js
文件的tslint,默认为 false。
回答by Jaan Oras
I don't have enough information about project setup and code, but it looks like you are trying to load .js
files as typescript.
我没有关于项目设置和代码的足够信息,但看起来您正在尝试将.js
文件加载为打字稿。
To use JavaScript files in Typescript projects you must enable allowJs
flag, either in command line --allowJs
or in the tsconfig.json
as "allowJs": true
.
要在 Typescript 项目中使用 JavaScript 文件,您必须allowJs
在命令行--allowJs
或tsconfig.json
as 中启用标志"allowJs": true
。
But, if the .js
files should not be part of the TS project but just are in the same directory tree, you need to review your exclude
and include
properties of tsconfig.json
但是,如果该.js
文件不应该是TS项目的一部分,但只是在同一个目录树,你需要检查你exclude
和include
性能tsconfig.json