Error "TS1005: ';' expected "when compiling class with TypeScript

0

I am studying TypeScript classes through official documentation: link . I used exactly the same sample code from 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 run the tsc greeter.ts command to compile the above code, I'm getting the following error:

  

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

What's wrong?

    
asked by anonymous 11.10.2017 / 13:55

1 answer

0

The problem was occurring because you were using the 1.0.3.0 version of TypeScript. To fix the problem, I had to uninstall the package that was being used ( npm uninstall -g typescript ) and install the latest version: npm install -g typescript@latest .

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

  

Version 1.0.3.0

.

I checked the path of the 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.0\

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

Important detail: I'm using Windows 7. I do not know if the same problem applies to other operating systems.

    
11.10.2017 / 14:50