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
:
But in my laptop(windows 7 x64),the command tsc --version
show message TS6029: Version 1.6.2
:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With