Tag Archives: TS1005

Error ts1005: ‘;’ expected

function sayHello(person: string) {
  return 'Hello, ' + person;
}

let user = 'Tom'
console.log(sayHello(user));

hello.ts
tsc hello.ts
An error

E:\source\develop\typescript\typescriptstudy\hello.ts(5,5): error TS1005: ';' expected.

The actual test found that changing let to var did not report the error.
the error message doesn’t say the wrong semicolon, it says the compiler can’t recognize the let keyword.
Running tsc-v
found version 1.0.3.0
Then I learned online that Typescript supports let syntax in 1.4. Just open the Windows environment variable and see where TSC is using the command, if the version is wrong.
The following statement is found in path within the Windows environment variable:
C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.0;
seems to be using the 1.0 that comes with the system.
Delete the environment variable here. Also delete Typescript 1.0 under the path. Let’s reinstall it

npm install -g typescript@latest

finally run:
tsc-v
found this time is not 1.0.3.0 but the latest installation 3.8.3. No problem.