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.
Read More:
- TS Failed to Use hasOwnProperty Method [How to Fix]
- ionic4- error TS2307: Cannot find module ‘rxjs-compat/Observable’
- Vue + TS reports an error after configuring the path alias
- error TS2339:Property ‘length’ does not exist on type ‘object’
- SSIS Exception: Failed to retrieve long data for column “TS_Description”
- Trivia: How does R language solve Error in ts(x):’ts’ object must have one or more observations
- After vscode installs ts, TSC compiles and generates JS, and an error is reported (repeated variables, etc.)
- Expected primary expression before ‘unsigned’ solution
- error: expected unqualified-id before ‘int’
- Expected indentation of 6 spaces but found 10
- JAVA lambda Syntax error on tokens, Expression expected instead
- Error: expected class name before ‘{‘ token
- Expected unqualified ID before numeric constant
- How to Fix “junit.framework.Comparison Failure Expected: but was”
- error: expected declaration or statement at end of input
- Expected unqualified ID before string constant
- syntax error on token “catch”,Identifier expected
- C language error: expected declaration or statement at end of input
- ValueError: not enough values to unpack (expected 6, got 1)