typescript 打字稿错误 TS1005: ';' 预期(二)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/46398916/
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
TypeScript error TS1005: ';' expected (II)
提问by StockUberflow
First of all, I've already seen the other posts about error TS1005. Same error code, but totally different.
首先,我已经看过其他关于错误 TS1005 的帖子。相同的错误代码,但完全不同。
A simple let x: number;
will generate the error TS1005
during compilation. It's not about a missing semicolon as what the error message says, but the compiler does not recognize the let keyword. I read that maybe because of an outdated compiler.
一个简单的let x: number;
将error TS1005
在编译期间生成。这与错误消息所说的缺少分号无关,而是编译器无法识别 let 关键字。我读到这可能是因为一个过时的编译器。
Here's my typescript version installed using npm install -g typescript
这是我安装的打字稿版本 npm install -g typescript
- TypeScript version:
2.5.2
- Compiler (tsc) version:
1.0.3.0
- 打字稿版本:
2.5.2
- 编译器 (tsc) 版本:
1.0.3.0
Maybe somebody can help?
也许有人可以帮忙?
回答by Bruno Grieder
Your installation is wrong; you are using a very old compiler version (1.0.3.0).
你的安装有误;您使用的是非常旧的编译器版本 (1.0.3.0)。
tsc --version
should return a version of 2.5.2.
tsc --version
应该返回 2.5.2 的版本。
Check where that old compiler is located using: which tsc
(or where tsc
) and remove it.
使用:(which tsc
或where tsc
)检查旧编译器所在的位置并将其删除。
Try uninstalling the "global" typescript
尝试卸载“全局”打字稿
npm uninstall -g typescript
Installing as part of a local dev dependency of your project
作为项目的本地开发依赖项的一部分安装
npm install typescript --save-dev
Execute it from the root of your project
从项目的根目录执行它
./node_modules/.bin/tsc
回答by venergiac
On Windowsyou can have in your PATH
在 Windows 上,您可以在 PATH 中拥有
PATH = ...;C:\Program Files (x86)\Microsoft SDKs\TypeScript.0\; ...
remove it from PATH env, then
从 PATH env 中删除它,然后
npm install -g typescript@latest
it worked for me to solve the
它对我来说解决了
"TypeScript error TS1005: ';' expected"
"打字稿错误 TS1005: ';' 预期的”
See also how to update TypeScript to latest version with npm?
回答by Yairopro
You haven't the last version of typescript.
你还没有打字稿的最新版本。
Running :
跑步 :
npm install -g typescript
npm
checks if tsc
command is already installed.
npm
检查tsc
命令是否已经安装。
And it might be, by another software like Visual Studio
. If so, npm
doesn't override it. So you have to remove the previous deprecated tsc
installed command.
而且它可能是由像其他软件Visual Studio
。如果是这样,npm
不要覆盖它。因此,您必须删除以前不推荐使用的已tsc
安装命令。
Run where tsc
to know its bin location. It should be in C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.0\
in windows. Once found, delete the folder, and re-run npm install -g typescript
. This should now install the last version of typescript.
运行where tsc
以了解其垃圾箱位置。它应该C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.0\
在窗口中。找到后,删除该文件夹,然后重新运行npm install -g typescript
. 现在应该安装最新版本的打字稿。
回答by Manohar Reddy Poreddy
The issue was in my code.
问题出在我的代码中。
In large code base, issue was not clear.
在大型代码库中,问题不明确。
A simplified code is below:
一个简化的代码如下:
Bad:
坏的:
collection.insertMany(
[[],
function (err, result) {
});
Good:
好的:
collection.insertMany(
[],
function (err, result) {
});
That is, the first one has [[], instead of normal array []
也就是说,第一个有[[],而不是普通的数组[]
TS error was not clear enough, and it showed error in the last line with });
TS错误不够清楚,最后一行用})显示错误;
Hope this helps.
希望这可以帮助。
回答by CyberMessiah
I had today a similar error message. What was peculiar is that it did not break the Application. It was running smoothly but the command prompt (Windows machine) indicated there was an error. I did not update the Typescript version but found another culprit. It turned there was a tiny omission of symbol - closing ")", which I believe The Typescript is compensating for. Just for reference the code is the following:
我今天收到了类似的错误消息。奇怪的是它没有破坏应用程序。它运行顺利,但命令提示符(Windows 机器)指示存在错误。我没有更新 Typescript 版本,但发现了另一个罪魁祸首。原来有一点符号遗漏 - 关闭“)”,我相信 Typescript 正在弥补这一点。代码如下,仅供参考:
[new Object('First Characteristic','Second Characteristic',
'Third Characteristic'*]
* notice here the ending ")" is missing.
Once brought back no more issues on the command prompt!
一旦在命令提示符下不再出现问题!
回答by Atul Jadhav
Remove
C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.0
directory.Now run :
npm install -g typescript
this will install the latest version and then re-try.
删除
C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.0
目录。现在运行:
npm install -g typescript
这将安装最新版本,然后重试。
回答by celikz
Just try to without changing anything
npm install [email protected]
X.X.X is your current version
尝试不做任何更改
npm install [email protected]
XXX 是您当前的版本
回答by user1892777
I was injecting service like this:
我正在注入这样的服务:
private messageShowService MessageShowService
instead of:
代替:
private messageShowService: MessageShowService
and that was the reason of error, despite nothing related with ','
was there.
这就是错误的原因,尽管与','
那里没有任何关系。
回答by user-12410035
If you're getting error TS1005: 'finally' expected.
, it means you forgot to implement catch
after try
. Generally, it means the syntax you attempted to use was incorrect.
如果您得到error TS1005: 'finally' expected.
,则意味着您忘记catch
在try
. 通常,这意味着您尝试使用的语法不正确。