Typescript中的解构导致编译器错误TS1008和TS1005

时间:2015-09-19 03:10:09

标签: compiler-errors typescript destructuring

我想在typescript中使用destructuring,示例代码:

var {first, second} = { first: "one", second: "two" }
console.log(first);

我的编译命令tsc --t es5 destructuring.ts

打字稿版本1.6.2

IDE是vs code

然后导致三个错误:

destructuring.ts(1,5): error TS1008: Unexpectedtoken; 'identifier' expected.

destructuring.ts(1,21): error TS1008: Unexpected token; 'module, class, interface, enum, import or statement' expected.

destructuring.ts(1,45): error TS1005: ';' expected.;

在我的桌面(窗口8.1 x64 )中,命令npm -g list,显示typescript@1.6.2,命令tsc --version显示Version 1.0.3.0

typescript 1.0.3.0

但在我的笔记本电脑( windows 7 x64 )中,命令tsc --version显示message TS6029: Version 1.6.2typescript 1.6.2

1 个答案:

答案 0 :(得分:5)

我能够在以前版本的TypeScript中重现您的问题,但不能在1.6.2中重现您的问题:

> tsc -v
Version 1.0.3.0
> tsc -t es5 destructuring.ts
error TS1008: Unexpected token; 'identifier' expected.
error TS1008: Unexpected token; 'module, class, interface, enum ...
error TS1005: ';' expected.

> tsc -v
message TS6029: Version 1.6.2
> tsc -t es5 destructuring.ts
>

请确保您在Visual Studio代码中实际使用的是TypeScript版本> = 1.5。

要修复桌面以使用正确版本的TypeScript,请查看this answer。基本上,您可以通过键入命令tsc来查看运行where tsc的位置,并且必须从路径中删除该目录或删除该目录。

相关问题