"TS1005: ';' expected" error when compiling class with Typescript

Asked

Viewed 3,402 times

2

I am studying Typescript classes through official documentation: https://www.typescriptlang.org/docs/handbook/classes.html. I used exactly the same example code as the documentation:

class Greeter {
    greeting: string;
    constructor(message: string) {
        this.greeting = message;
    }
    greet() {
        return "Hello, " + this.greeting;
    }
}

let greeter = new Greeter("world");

However, when trying to execute the command tsc greeter.ts to compile the above code, I am getting the following error:

\greeter.ts(13,5): error TS1005: ';' expected.

What is wrong?

  • I couldn’t reproduce the problem (I can’t paste the code URL to see). Put here and see: https://www.typescriptlang.org/play/index.html

  • Here worked correctly, tries to reinstall the node-typescript. Take a look to see if you are getting the right file too, because the code you put only has 11 lines and it is giving error on line 13.

  • Running the Tsc -v command gives the following result: Version 1.0.3.0. It already rode npm update typescript and npm install -g typescript@latest, but the version does not update. I am doing this test on a Windows 7 computer, it may have some relationship?

1 answer

2

The problem was occurring by using the version 1.0.3.0 typescript. To troubleshoot the problem, I needed to uninstall the package being used (npm uninstall -g typescript) and install the latest version: npm install -g typescript@latest.

Even after updating the typescript version via npm, the command tsc -v still returned the value:

Version 1.0.3.0

.

I went to check the path of tsc configured in my PATH and saw that it was pointing to a file other than the one installed by npm: C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.0\

I updated the Tsc path in the PATH to the npm package installation location: C:\Users\marcell.alves\AppData\Roaming\npm\node_modules\typescript\bin and the code was compiled correctly.

Important detail: I am using Windows 7. I don’t know if the same problem applies to other operating systems.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.