我正在运行tsc -w -p myfile.ts,并且在阅读打字稿教程时遇到错误。无论文件内容如何,错误似乎都会引发。
我的文件:
1 function greeter(person: string) {
2 return "Hello, " + person;
3 }
4
5 const user = "Jane User";
6
7 console.log(greeter(user));
错误:
linkedlist.ts(1,1): error TS1005: '{' expected.
linkedlist.ts(1,1): error TS1327: String literal with double quotes expected.
linkedlist.ts(1,10): error TS1005: ':' expected.
linkedlist.ts(1,10): error TS1328: Property value can only be string literal, numeric literal, 'true', 'false', 'null', object literal or array literal.
linkedlist.ts(1,24): error TS1005: ',' expected.
linkedlist.ts(1,34): error TS1005: ',' expected.
linkedlist.ts(2,5): error TS1327: String literal with double quotes expected.
linkedlist.ts(2,12): error TS1005: ':' expected.
linkedlist.ts(2,12): error TS1328: Property value can only be string literal, numeric literal, 'true', 'false', 'null', object literal or array literal.
linkedlist.ts(2,30): error TS1005: ',' expected.
linkedlist.ts(5,1): error TS1012: Unexpected token.
13:23:59 - Found 11 errors. Watching for file changes.
已修复: :使用tsconfig.json文件删除错误
答案 0 :(得分:0)
您使用哪个版本的TS编译器?这很可能是旧版本。
TypeScript 3.3应该是。检查您的版本:
tsc -v
尝试在全球范围内重新安装:
npm uninstall -g typescript
然后:
npm install -g typescript@latest