I am trying to learn Typescript and I'm following the tutorial on this page: https://www.typescriptlang.org/docs/handbook/functions.html. When I create a file cardPicker.ts and paste the following code, it won't compile. I get this error 5 times: Typescript error TS1005: ';' expected. Lines 1,6,7,14 and 15. I don't see where a semicolon is missing, but maybe the error message means something else. I'm concerned about my version of ts, but I just installed that two weeks ago. When I do "tsc -version" it says 1.0.3.0
let deck = {
suits: ["hearts", "spades", "clubs", "diamonds"],
cards: Array(52),
createCardPicker: function() {
return function() {
let pickedCard = Math.floor(Math.random() * 52);
let pickedSuit = Math.floor(pickedCard / 13);
return {suit: this.suits[pickedSuit], card: pickedCard % 13};
}
}
}
let cardPicker = deck.createCardPicker();
let pickedCard = cardPicker();
alert("card: " + pickedCard.card + " of " + pickedCard.suit);
I compile the project by running "tsc cardPicker.ts" in the command line.
Edited to add years later: Wanted to make it clear, I did not realize I had two versions of typescript on my computer- one was installed with Visual Studio a while back, and it was using that. Once I switched to use the node.js command prompt like bug-a-lot suggested in their answer below, it used the correct version. Using a regular windows command prompt, I could get it to work by navigating to the folder where tsc is found. It then successfully compiled without any changes to the code.