typescript Visual Studio Code:[js] 类型只能在 .ts 文件中使用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/41320266/
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
Visual Studio Code:[js] types can only be used in a .ts file
提问by TheSoul
Is it possible to use .js files in a typescript project in vs code? I have clone a react-native project from a github repository and opened it in visual studio code. When I add a tsconfig.json in order to start using typescript, I get a long list of errors. For example here is a drawer.jsfile (with es6 features):
是否可以在 vs 代码的打字稿项目中使用 .js 文件?我从 github 存储库克隆了一个 react-native 项目并在 Visual Studio 代码中打开它。当我添加 tsconfig.json 以开始使用打字稿时,我收到一长串错误。例如,这是一个drawer.js文件(具有 es6 功能):
Here is my tsconfig.json file (If I remove this file then every thing works fine, no error reported) :
这是我的 tsconfig.json 文件(如果我删除此文件,则一切正常,不会报告错误):
回答by Swapnil Patwa
Workaround - Add the following configuration in $workspace/.vscode/settings.json
解决方法 - 在中添加以下配置 $workspace/.vscode/settings.json
{
"javascript.validate.enable": false
}
回答by RoRFan
I restarted VS code and the error was gone, just in case it helps
我重新启动了 VS 代码,错误消失了,以防万一
回答by Alex Alberto Robaina
You can try with this!!!
你可以试试这个!!!
Install in your visual studio code the extension Flow Language Support and disable TypeScript and JavaScript Language Features
在您的 Visual Studio 代码中安装扩展 Flow Language Support 并禁用 TypeScript 和 JavaScript 语言功能
Search @builtin TypeScript and JavaScript Language Features and reload.
搜索 @builtin TypeScript 和 JavaScript 语言功能并重新加载。
You can see this solutions https://stackoverflow.com/questions/48859169
你可以看到这个解决方案 https://stackoverflow.com/questions/48859169
Its important install npm for flow
其重要的安装 npm for flow
回答by sleepwalkerfx
You're missing a ,
comma between type
and { Action }
in line 2.
您在第 2 行和,
之间缺少逗号。type
{ Action }