Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Destructuring in Typescript cause compiler errors TS1008 and TS1005

I wanna use destructuring in typescript,example code:

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

my compile command tsc --t es5 destructuring.ts,

typescript version 1.6.2,

IDE is vs code.

then cause three errors:

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.;

In my desktop(window 8.1 x64),command npm -g list ,show [email protected],and command tsc --version show Version 1.0.3.0:

typescript 1.0.3.0

But in my laptop(windows 7 x64),the command tsc --version show message TS6029: Version 1.6.2: typescript 1.6.2

like image 548
codelegant Avatar asked Sep 19 '15 03:09

codelegant


1 Answers

I am able to reproduce your problem in past versions of TypeScript, but not 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
>

Please ensure you are actually using a version of TypeScript >= 1.5 in Visual Studio Code.

To fix your desktop to use the right version of TypeScript take a look at this answer. Basically, you can see where tsc is running from by typing the command where tsc and you have to remove that directory from the path or delete that directory.

like image 145
David Sherret Avatar answered Sep 30 '22 14:09

David Sherret