I've been diving into Typescript and following a tutorial located at the link: https://www.typescriptlang.org/docs/handbook/functions.html. As I proceeded to create a file named cardPicker.ts and inserted the provided code, compilation issues arose. Specifically, I encountered the Typescript error TS1005 five times, mentioning that a semicolon is expected on lines 1, 6, 7, 14, and 15. Despite carefully inspecting my code, I couldn't pinpoint where a semicolon was missing. Perhaps there's another underlying cause for this error message. Concerns regarding the version of ts I'm using also surfaced, even though I recently installed it two weeks ago. Running "tsc -version" revealed version 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);
To compile the project, I utilized the command line and executed "tsc cardPicker.ts".
An update years later reveals that I had unknowingly had two versions of TypeScript on my system- one from a previous Visual Studio installation, causing conflicts. Following bug-a-lot's suggestion in their answer below, switching to the node.js command prompt resolved this issue by using the correct version. Alternately, using a standard Windows command prompt required navigating to the tsc-containing folder for successful compilation without any alterations to the code.