typescript Angular2(或TypeScript)中的“预期声明或声明”错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30214022/
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-10-21 03:00:22  来源:igfitidea点击:

"Declaration or statement expected" Error in Angular2 (or TypeScript)

typescriptangular

提问by Chu Son

I'm completely new to Angular2 and TypeScript. I'm following Tutorial but I keep coping this error. Is it an error caused by the compiler or something?

我对 Angular2 和 TypeScript 完全陌生。我正在关注教程,但我一直在处理这个错误。是编译器引起的错误还是什么?

enter image description here

在此处输入图片说明

回答by Fenton

It looks like you are using an older version of the compiler.

看起来您使用的是旧版本的编译器。

You need to download and install the TypeScript 1.5 beta(or newer) in order to use ES6 style imports and annotations.

您需要下载并安装TypeScript 1.5 beta(或更新版本)才能使用 ES6 样式导入和注释。

You can check the version you currently have installed using:

您可以使用以下方法检查当前安装的版本:

tsc --version

It should give you Version 1.5.0-beta.

它应该给你Version 1.5.0-beta

If you already have it installed, perhaps your PATHvariable still points to the old folder, so edit your PATH variable to point to the latest folder, i.e.

如果你已经安装了它,也许你的PATH变量仍然指向旧文件夹,所以编辑你的 PATH 变量以指向最新的文件夹,即

C:\Program Files (x86)\Microsoft SDKs\TypeScript.5\;

回答by webdevinci

Since you didn't accept the answer, I assume you are on OSx?

由于您没有接受答案,我假设您使用的是 OSx?

I had 2 instances of TS installed on my machine, I needed to point to the correct/newer one. Try this:

我的机器上安装了 2 个 TS 实例,我需要指向正确的/较新的实例。试试这个:

In Webstorm goto Preferences (Command + ,) -> Languages -> Typescript.

在 Webstorm 中转到 Preferences (Command + ,) -> Languages -> Typescript。

Command Line Options:

命令行选项:

-m amd -t ES5

-m amd -t ES5

Compiler Versions:

编译器版本:

/usr/local/lib/node_modules/typescript/lib

/usr/local/lib/node_modules/typescript/lib

This way it will grab your global typescript instead of the one Webstorm may have set to default for you.

通过这种方式,它将抓取您的全局打字稿,而不是 Webstorm 可能为您设置的默认打字稿。