typescript ['type aliases' 只能在 .ts 文件中使用]
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/48852007/
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
['type aliases' can only be used in a .ts file]
提问by thana
回答by ishandutta2007
This is what you need to do with VS Code, observe the gif carefully
这就是你需要用VS Code做的,仔细观察gif
Steps to resolve error
1. Go to extension
2. Click on more (...) and select Show Built-in extension
3. Search "TypeScript and JavaScript Language Features" - yellow & blue icon
4. Click on Setting icon of extension and select Disable (workspace)
5. Click on Reload / Restart Required
回答by pashute
If you are getting this in React Native its probably a known bug in VSCode, that when Google Flow (which competes with MS Typescript) is coded, shows errors erroneously mentioning Typescript.
如果你在 React Native 中得到这个,它可能是 VSCode 中的一个已知错误,当 Google Flow(与 MS Typescript 竞争)被编码时,会显示错误地提到 Typescript 的错误。
Your current .js code is supposed to be preprocessed by Flow into another .js file with "proper" js.
您当前的 .js 代码应该由 Flow 预处理到另一个带有“适当”js 的 .js 文件中。
So make sure Flow is installedand then disable the Typescript parsing support. Here's the official answer on the Flow installation webpage:
因此,请确保安装了 Flow,然后禁用 Typescript 解析支持。下面是 Flow 安装网页上的官方回答:
Set javascript.validate.enable option to false or completely disable the built-in TypeScript extension for your project (see gif below)...
将 javascript.validate.enable 选项设置为 false 或完全禁用项目的内置 TypeScript 扩展(请参阅下面的 gif)...
Otherwise, you may want to stay as is and just change your code as suggested by C2P1 on March 19, 2018 on the github issue 631
否则,您可能希望保持原样,只需按照 C2P1 于 2018 年 3 月 19 日在github 问题 631上的建议更改您的代码
To disable the [js] parser (connected to Typescript),
要禁用 [js] 解析器(连接到 Typescript),
In VSCode menu: File -> Preferences -> User settings
, (or ctrl+,
) and add the following line
在 VSCode 菜单中:File -> Preferences -> User settings
, (或ctrl+,
)并添加以下行
"javascript.validate.enable": false,
This answer was completed after seeing Idan Dagan's answer (Not the accepted answer) here: js 'types' can only be used in a .ts file - Visual Studio Code using @ts-check
这个答案是在看到 Idan Dagan 的答案(不是接受的答案)之后完成的:js 'types' can only be used in a .ts file - Visual Studio Code using @ts-check
And here's an excellent albeit old page about setting up the react-native environment, from Hackernoon. (You also have the VSCode React-native-full plugin)
而且这里是一个很好的老虽然网页有关设置反应天然环境,从Hackernoon。(你也有 VSCode React-native-full 插件)
回答by Agung Pramono
Just disable built-in extension for TypeScript in VSCode. On the VSCode Extensions choose "Show Built-in Extensions" and then search for "TypeScript and JavaScript Language Features", Click disable then reload the VSCode. It works for me
只需在 VSCode 中禁用 TypeScript 的内置扩展即可。在 VSCode 扩展上选择“显示内置扩展”,然后搜索“ TypeScript 和 JavaScript 语言功能”,单击禁用然后重新加载 VSCode。这个对我有用
回答by Joe
This is what you are looking for. Unfortunately I haven't Googled a proper solution but we have to disable some JS checking.
这就是你要找的。不幸的是,我还没有在 Google 上搜索到合适的解决方案,但我们必须禁用一些 JS 检查。
回答by G. Desenv
I've solved this with a plugin for VSCode "Flow Language Support". It will control the errors of the code instead of the plug-in TS-JS (built-in plugin of VS Code). In Details of plugin, guides you how to disable the original plugin TS-JS VSCode.
我已经用 VSCode“流语言支持”插件解决了这个问题。它将控制代码的错误而不是插件 TS-JS(VS Code 的内置插件)。在插件的详细信息中,指导您如何禁用原始插件 TS-JS VSCode。