TypeScript error TS1005: ';' expected (II)

Typescript

Typescript Problem Overview


First of all, I've already seen the other posts about error TS1005. Same error code, but totally different.

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.

Here's my typescript version installed using npm install -g typescript

  • TypeScript version: 2.5.2
  • Compiler (tsc) version: 1.0.3.0

Maybe somebody can help?

Typescript Solutions


Solution 1 - Typescript

Your installation is wrong; you are using a very old compiler version (1.0.3.0).

tsc --version should return a version of 2.5.2.

Check where that old compiler is located using: which tsc (or where tsc) and remove it.

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

Solution 2 - Typescript

On Windows you can have in your PATH

PATH = ...;C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.0\; ...

remove it from PATH env, then

npm install -g typescript@latest

it worked for me to solve the

> "TypeScript error TS1005: ';' expected"

See also https://stackoverflow.com/questions/39677437/how-to-update-typescript-to-latest-version-with-npm

Solution 3 - Typescript

You don't have the last version of typescript.

Running :

npm install -g typescript

npm checks if tsc command is already installed.

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.

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.

Solution 4 - Typescript

I faced the same error. After banging my head for half an hour, I found one Romeo bracket hanging around without his Juliet LOL...!(the opening and closing brackets were mismatching) Please check all your brackets to avoid such errors.

Solution 5 - Typescript

> 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 });

Hope this helps.

Solution 6 - Typescript

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:

[new Object('First Characteristic','Second Characteristic',
'Third Characteristic'*] 

* notice here the ending ")" is missing.

Once brought back no more issues on the command prompt!

Solution 7 - Typescript

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

Solution 8 - Typescript

Just try to without changing anything npm install [email protected] X.X.X is your current version

Solution 9 - Typescript

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.

Solution 10 - Typescript

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.

Solution 11 - Typescript

Stupid issue with minor mistake;

i was trying

const quizType = computed(() => rootState.quizzes.quiz

const res = await noAuthApi.getQuizzes(quizType)

and the issue was, i missed the closing bracket. it should be like

const quizType = computed(() => rootState.quizzes.quiz)

const res = await noAuthApi.getQuizzes(quizType)

Solution 12 - Typescript

Verify extension of file. File containing tsx should have .tsx extension.

Solution 13 - Typescript

in my case I'd the 'function' keyword. I'd to remove it.

Bad:

export class CustomValidators {

static function myFunc(x: string) { console.log(x) } }

Good:

export class CustomValidators {

static myFunc(x: string) { console.log(x) } }

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionStockUberflowView Question on Stackoverflow
Solution 1 - TypescriptBruno GriederView Answer on Stackoverflow
Solution 2 - TypescriptvenergiacView Answer on Stackoverflow
Solution 3 - TypescriptYairoproView Answer on Stackoverflow
Solution 4 - TypescriptHarini KrishnaView Answer on Stackoverflow
Solution 5 - TypescriptManohar Reddy PoreddyView Answer on Stackoverflow
Solution 6 - TypescriptCyberMessiahView Answer on Stackoverflow
Solution 7 - TypescriptAtul JadhavView Answer on Stackoverflow
Solution 8 - TypescriptcelikzView Answer on Stackoverflow
Solution 9 - Typescriptuser1892777View Answer on Stackoverflow
Solution 10 - Typescriptuser-12410035View Answer on Stackoverflow
Solution 11 - TypescriptSeetpal singhView Answer on Stackoverflow
Solution 12 - TypescriptYuvraj PatilView Answer on Stackoverflow
Solution 13 - TypescriptRT.View Answer on Stackoverflow