Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

enter image description here

like image 380
Chu Son Avatar asked May 13 '15 11:05

Chu Son


People also ask

How do you fix a declaration or statement expected?

If you use IntelliJ as your IDE and are getting the "Declaration or statement expected" error, try closing and re-opening the file or restarting your IDE as it sometimes glitches. Make sure you aren't using any reserved words when declaring variables.

What is TS1128?

Typescript ERROR TS1128: Declaration or statement expected. 201. Angular CLI Error: The serve command requires to be run in an Angular project, but a project definition could not be found. 174.

What is expression expected error?

The "Expression expected" TypeScript error occurs when we have a syntax error in our code or our code editor is using an older version of TypeScript. To solve the error, make sure to correct and syntax errors and use a recent version of the TypeScript compiler.


2 Answers

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.

You can check the version you currently have installed using:

tsc --version

It should give you Version 1.5.0-beta.

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

C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.5\;
like image 117
Fenton Avatar answered Oct 04 '22 03:10

Fenton


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

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

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

Command Line Options:

-m amd -t ES5

Compiler Versions:

/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.

like image 26
webdevinci Avatar answered Oct 04 '22 05:10

webdevinci