Typescript destruction causes TS1008 and TS1005 compiler errors

I want to use destructuring in typescript, sample code:

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

my tsc --t es5 destructuring.ts compilation tsc --t es5 destructuring.ts ,

typescript version 1.6.2 ,

IDE - vs code .

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

On my desktop (window 8.1 x64), the npm -g list command, show typescript@1.6.2 and the tsc --version show tsc --version Version 1.0.3.0 :

typescript 1.0.3.0

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

+5
source share
1 answer

I can 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 make sure that you are actually using TypeScript version> = 1.5 in Visual Studio Code.

To fix your desktop to use the correct TypeScript version, check out this answer . Basically, you can see where tsc is tsc from by typing where tsc , and you need to remove this directory from the path or delete this directory.

+5
source

All Articles