Error TS1005 in Typescript is indicating that it is expecting a semicolon somewhere in the code, but I am unable to locate where the semicolon is missing

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.

Answer №1

Perhaps when you were setting up tsc, you may have utilized npm install tsc -g

Upon checking out this link: https://www.npmjs.com/package/tsc it appears that this package has been discontinued.

It is now recommended to use npm install typescript -g as it will provide you with the latest version.

Currently, executing tsc -v yields Version 2.8.1

The updated version should help resolve any issues related to ts1005.

Answer №2

Is that all the code you have in your TypeScript file? Or do you also include some reference comments?

The error message is not about a missing semicolon, since TypeScript does not require them like JavaScript. The issue might be related to another part of your code that the compiler finds confusing, such as an incomplete declaration.

For instance:

let deck: Number of Date;

This would result in the specific error mentioned.

Depending on how your setup is configured, you may be compiling more than expected. In this case, it could be due to using an outdated version of TypeScript that doesn't recognize newer syntax introduced after version 1.4, like the let keyword.

UPDATE

To clarify, even though you installed the latest version of TypeScript, you need to run commands in the node.js command prompt instead of the regular Windows command prompt, especially if you are using Windows.

Answer №3

Hello @Kelli! I encountered the same error, but managed to resolve it successfully. If you are using Visual Studio, simply paste your code into Visual Studio Code and set the language to TypeScript. You will notice red markers where there are misspellings - make sure to indent your code properly and ensure that all opening and closing brackets are correctly placed, as well as adding semicolons where necessary.

Answer №4

Today, I dedicated a couple of hours to troubleshooting a similar issue in my CSS pre-processor (my particular error message involved a missing comma).

 error TS1005: ',' expected

It turned out that the culprit was some stray backtick characters within comments in my LESS files, causing confusion for the pre-processor. Perhaps it's due to the use of TypeScript in the project (Angular 5) where backticks have special significance.

Answer №5

I encountered a very strange error similar to this:

It took me longer than expected to realize that the path was duplicated.

src/app/services/ was mistakenly nested within src/app/services/MYPROJECT. This error was caused by an incorrect path in the code generation process, and I failed to notice the additional files present.

src/app/services/MYPROJECT.NG/src/app/services/api/rr.api.ts(972,19): error TS1005: ';' expected.
src/app/services/MYPROJECT.NG/src/app/services/api/rr.api.ts(974,10): error TS1128: Declaration or statement expected.
src/app/services/MYPROJECT.NG/src/app/services/api/rr.api.ts(975,17): error TS1005: ';' expected.
src/app/services/MYPROJECT.NG/src/app/services/api/rr.api.ts(976,17): error TS1005: ';' expected.
src/app/services/MYPROJECT.NG/src/app/services/api/rr.api.ts(977,24): error TS1005: ';' expected.
src/app/services/MYPROJECT.NG/src/app/services/api/rr.api.ts(978,17): error TS1005: ';' expected.
src/app/services/MYPROJECT.NG/src/app/services/api/rr.api.ts(986,4): error TS1128: Declaration or statement expected.
src/app/services/MYPROJECT.NG/src/app/services/api/rr.api.ts(987,24): error TS1005: ';' expected.
src/app/services/MYPROJECT.NG/src/app/services/api/rr.api.ts(988,20): error TS1005: ';' expected.
src/app/services/MYPROJECT.NG/src/app/services/api/rr.api.ts(989,13): error TS1005: ';' expected.
src/app/services/MYPROJECT.NG/src/app/services/api/rr.api.ts(990,13): error TS1005: ';' expected.
src/app/services/MYPROJECT.NG/src/app/services/api/rr.api.ts(991,25): error TS1005: ';' expected.
src/app/services/MYPROJECT.NG/src/app/services/api/rr.api.ts(992,15): error TS1005: ';' expected.
src/app/services/MYPROJECT.NG/src/app/services/api/rr.api.ts(993,21): error TS1005: ';' expected.
src/app/services/MYPROJECT.NG/src/app/services/api/rr.api.ts(994,20): error TS1005: ';' expected.
src/app/services/MYPROJECT.NG/src/app/services/api/rr.api.ts(996,6): error TS1128: Declaration or statement expected.
src/app/services/MYPROJECT.NG/src/app/services/api/rr.api.ts(997,14): error TS1005: ';' expected.

Answer №6

Encountering this problem is not uncommon. It can often be attributed to a discrepancy between the versions of Angular and TypeScript being used. To resolve this issue, simply follow the steps outlined below:

  1. Step 01 - Installing TypeScript for Visual Studio 2015

    • Download TypeScript for Visual Studio 2015
    • Prior to installation, verify if TypeScript is already present by checking the path C:\Program Files(x86)\Microsoft SDKs\TypeScript. If located, proceed to delete it.
    • Proceed with the installation, which should result in TypeScript being installed at C:\Program Files (x86)\Microsoft SDKs\TypeScript\3.2
    • Set the path for TypeScript by configuring the path variable as C:\Program Files (x86)\Microsoft SDKs\TypeScript\3.2
  2. Step 02 - Installing the latest version of Angular (Angular 7) using the following commands

    • npm install -g @angular/cli
    • npm install -g @angular/core
  3. Step 03 - Verifying the TypeScript version with the command below

    • ng version
    • This command will display the TypeScript version, e.g., 3.2.4 (from the previous step)

    • I would like to express my gratitude to Shahriar Morshed and TranslucentCloud for their valuable insights, which I utilized from their responses to effectively address my issue.

Answer №7

Curly braces can occasionally be absent in JSON.

For instance, the error can be corrected by inserting the two commented lines below:

const myObject =
[
  {
    'id': '123',
    'person': [
      {   // BRACE MISSING
        'name': 'SushiGuy',
        'age': '99',
      }   // BRACE MISSING
    ]
  }
];

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Using ngForm to implement multiselect options in HTML

Attempting to implement a multiselect dropdown that is tied to a dynamic property receiving data from a JSON script via service. Successfully displayed the data in the dropdown, but encountering abnormalities when adding the multiple attribute within the s ...

What is the best way to access a state variable that has a union data type?

Is there a way to access a field of a state variable with a union type in TypeScript? Here is an example of a zustand store I have defined: import { create } from 'zustand' type HeightUnit = 'cm' | 'ft\' in"&ap ...

Using Typescript: Generate keys in function return depending on parameter

Currently in the process of developing an SDK for a Rest API that includes an embed request parameter to fetch additional resources and add them to the response. I am exploring if there is a way, using Typescript, to extract these embed parameters while de ...

Making sure a value is a specific string in TypeScript

Here is what I currently have: type AppDisplay = "MainMenu" | "Game" | "GameOver"; interface AppState { appDisplay: AppDisplay } const initialAppState : AppState = { appDisplay: "MainMenu" } type ActionType = { type: "DisplayMenu" | "DisplayGame" ...

Checking the conditions and return statements within Jest testing framework

I recently started diving into Jest and am looking for alternative methods to test this function regarding the If case and return statement using Jest. Here is the function I need help testing: const extractInfo = (description: string) => { cons ...

What are the steps for creating and deploying a project that utilizes asp.net core on the server-side and Angular on the client-side

My latest project combines asp.net core 5 and angular 15 technologies for the backend and frontend, respectively. The asp.net core MVC portion of the project is contained in a dedicated folder named serverApi, while the angular part is generated in another ...

Using RxJS and the combineLatest function can be hit or miss in terms of reliability

When you call this function multiple times with the values of observables obs1 and obs2 being the same each time, the returned array may not always be the same. getUniqueProducts(obs1: Observable<any>, obs2: Observable<any>): Observable<any& ...

What is the primary purpose of the index.d.ts file in Typescript?

There are some projects that include all types declarations within the index.d.ts file. This eliminates the need for programmers to explicitly import types from other files. import { TheType } from './somefile.ts' Is this the proper way to use ...

Bovine without Redis to oversee queue operations

Can Bull (used for job management) be implemented without utilizing Redis? Here is a segment of my code: @Injectable() export class MailService { private queue: Bull.Queue; private readonly queueName = 'mail'; constructor() { ...

What are the best strategies for combining multiple TypeScript class decorators?

I have a set of unique class decorators that I apply to multiple classes. It looks something like this: @awesome @cool @amazing export class MySpecialClass { /* ..... */ } However, since I use these three decorators across many classes, I want to condens ...

Transferring object information to Backand using Ionic 2

I have developed a signup page using Ionic 2. In this signup page, I have included a dropdown menu for users to select their blood type. However, I am facing an issue where the selected blood type is not being sent to the Backand database as expected. I&ap ...

TypeScript async function that returns a Promise using jQuery

Currently, I am facing a challenge in building an MVC controller in TypeScript as I am struggling to make my async method return a deferred promise. Here is the signature of my function: static async GetMatches(input: string, loc?: LatLng):JQueryPromise& ...

Ways to access file attributes and transfer a file in ionic 4?

I am facing an issue while attempting to transfer a file from my mobile device to Google bucket using Ionic 4. Although I can successfully upload the file, I am struggling to extract its properties from the file object. Below is the method I am using: as ...

Ensuring TypeScript object types are safe by requiring all keys to be within an array of values

When working with Typescript ^3.8, we have an interface defined as follows: interface IEndpoint { method: 'get'|'put'|'post'|'patch'|'delete', path: string } Additionally, there is a constant declared like ...

Utilizing Typescript's compilerOptions.outDir for efficient compilation with external non-TS modules

I am encountering an issue with non-ts modules (text assets) not being transferred to the outDir as specified in tsconfig.json (or I might not be performing the task correctly). Here is a simple example to reproduce the issue: // /src/main.ts import text ...

Ways to send a variable to ngIf

header.component.html <ng-container *ngFor="let headerMenu of headerMenus"> <li *ngIf="headerMenu.ngif"> <a (click)="onClick(headerMenu.menu)" [class]="headerMenu.menu"> <img [src]="headerMenu.src" [alt]="heade ...

Exploring Typescript code through a practical example with reference to Uniswap's implementation

On the Uniswap website, I came across some code on the Swap page that caught my attention. You can find the code snippet in question at line 115 of the Uniswap GitHub repository. const { trade: { state: tradeState, trade }, allowedSlippage, cur ...

Utilize TypeScript with react-redux connect for seamless integration

As I attempt to create a React application in TypeScript using Redux and react-router-dom, I encountered some typing problems when integrating Redux. To address this issue, I decided to construct a minimal example containing only one page called test-page: ...

What are the steps to extract information from an observable?

Having trouble retrieving data from a request? I've encountered an issue where the data retrieved inside .subscribe in an observable function is returning as undefined when trying to access it outside the function. It's quite frustrating! Here i ...

Issue with 'index.d.ts' authentication compatibility in my Firebase development

Issue Error: node_modules/@firebase/auth-compat/dist/auth-compat/index.d.ts:53:421 - error TS1005: ',' expected. 53 import { type User, type Unsubscribe, type ActionCodeInfo, type UserCredential, type Auth, type IdTokenResult, type MultiFactorE ...