Typescript: Error in syntax. Token not expected

Recently, I've been attempting to run a .ts file as a console application. Despite successfully converting the .ts files to .js using tsc without any errors, I'm encountering an issue when trying to launch the .ts file with ts-node:

"SyntaxError: Unexpected token ..."

Upon reviewing my tsconfig.json file, the settings are as follows:

{
"compilerOptions": {
    "target": "es6",
    "module": "commonjs",
    "strict": true,
    "esModuleInterpop": rue
    }
} 

The TypeScript code snippet involved is as follows:

constructor(... pieces : IPiece[]){
super();
for (let i = 0; i < pieces.length; i++) {
    this.add(pieces[i]);
}}

This discrepancy leads me to believe that tsc and ts-node compile .ts files differently. Any suggestions or insights on this matter would be greatly appreciated. Thank you.

Answer №1

There is a small error in your tsconfig.json file code, where "esModuleInterpop" should be changed to true.

{
"compilerOptions": {
    "target": "es6",
    "module": "commonjs",
    "strict": true,
    "esModuleInterpop": true
    }
} 

Make the following edit:-

... pieces : IPiece[]

To this line, either add private or public.

constructor(public pieces : IPiece[]){ } //use public or private

Please try making these changes and let me know how it works out.

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

What is the best way to recycle a variable in TypeScript?

I am trying to utilize my variable children for various scenarios: var children = []; if (folderPath == '/') { var children = rootFolder; } else { var children = folder.childs; } However, I keep receiving the following error message ...

Conflicts arise when trying to create several objects with different material types in ThreeJS within the

Adding a star to the scene caused all objects in the scene to turn white and the perspective of the objects to glitch. Switching the materialStar to new THREE.MeshBasicMaterial fixed the rendering issue. It appears that the problem stems from having multip ...

How can I apply styling to Angular 2 component selector tags?

As I explore various Angular 2 frameworks, particularly Angular Material 2 and Ionic 2, I've noticed a difference in their component stylings. Some components have CSS directly applied to the tags, while others use classes for styling. For instance, w ...

Exploring the new possibilities of Angular 5: Enhanced REST API service with paginated data and object mapping capabilities

After implementing pagination in my REST API backend, I now need to update my Angular services to accommodate the changes. Instead of simply returning an array of objects, the API will now return JSON responses structured like this: { "count": 0, ...

ERROR UnhandledTypeError: Unable to access attributes of null (attempting to retrieve 'pipe')

When I include "{ observe: 'response' }" in my request, why do I encounter an error (ERROR TypeError: Cannot read properties of undefined (reading 'pipe'))? This is to retrieve all headers. let answer = this.http.post<ResponseLog ...

Guide on declaring numerous principals within an AWS CDK policy document

Currently, I am in the process of working with a cdk script and I have the need to specify multiple principals like so: "Principal": { "AWS": [ "arn:aws:iam::AWS-account-ID:user/user-name-1", "arn:aws:iam::AWS- ...

Tips for optimizing HttpRequests within nested for-loops that utilize subscribe()?

Our REST-API is designed to be frontend agnostic, meaning it always sends the IRI to nested resources. This results in multiple HTTP calls needed to retrieve data; first for the parent resource, then its child resources and so on. Each Country has linked E ...

Converting JSX files to TSX files: a step-by-step guide

I am facing an issue with this particular component on the website. It is currently in .jsx format while the rest of the website uses .tsx files. I need to convert this specific component into a .tsx file. Can someone provide assistance or guidance? Despit ...

Utilize a third-party module's repository within my module in NestJS

Currently, I am working on developing an application using Nestjs and have created two modules: User and Auth with the following structure: https://i.sstatic.net/N8Zyz.png To interact with the User entity, I needed to inject the UsersService into the Aut ...

Dealing with client-side exceptions in a Next.js 13 application's directory error handling

After carefully following the provided instructions on error handling in the Routing: Error Handling documentation, I have successfully implemented both error.tsx and global-error.tsx components in nested routes as well as the root app directory. However, ...

Creating a fresh dataset using a 2D array in node-gdal-async

I'm facing a challenge in JavaScript where I need to create a new dataset from a 2D array. Despite my efforts, I can't seem to figure out the necessary steps from the documentation. It seems that in order to create this new dataset, I must utili ...

Exploring methods of testing a simple React functional component using Jest, TypeScript, and type annotations

I have been struggling for a long time to find a straightforward example of how to test a simple react component using jest and typescript. Despite my efforts, I have not been successful in finding a solution. I have checked out: https://basarat.gitbooks.i ...

Exploring methods to successfully upload a blob to Firebase and modify it using cloud functions

For days now, I've been attempting to successfully upload a file to firestorage using firebase functions but haven't had any luck. This is the progress I've made so far: export const tester = functions.https.onRequest(async (request, respons ...

Issue with React/Typescript: using "any" for typehinting is ineffective

My React component is called github.tsx. Here is the code within it: import React from 'react' import axios from 'axios' class Github extends React.Component<{any, any}>{ state = { user: [] } getRepoUser = async () ...

React Scheduler by Bryntum

After successfully discovering some functions related to various actions, I find myself still in need of additional functions: Currently, I am utilizing these functions by passing them directly as props to the Scheduler React Component: - onBeforeEventSa ...

Proper way to link another class in typegoose (mongoose) and store only the reference (ObjectId)?

When attempting to save certain fields in ObjectId only in the mongo db, I encountered an issue with the code below: @ObjectType() export class User { @prop() @Field() name: string; @prop({ ref: () => OtherClassA }) @Field() otherClassA: Ot ...

When converting an object into a specific type, the setter of the target type is not invoked

Imagine a scenario with a class structured like this: class Individual { private _name: string; get Name(): string { return this._name; } set Name(name: string) { this._name = name; } } Upon invoking HttpClient.get<Individual>(), it retrieve ...

Connect one router to another router within the Oak framework, similar to how it is done in

I have a goal of setting up multiple routers along with a main router that can route requests to the other routers. router.use("/strategy", strategyRoutes); router.use("/account", accountRoutes); The objects router, strategyRoutes, and ...

Angular unable to retrieve data using Angularfire2

Having trouble retrieving data from the Real time Database on firebase. Read and Write permissions are set to public so no authentication is needed. The npm compilation is successful, indicating that the Angular-CLI code is correct. Following the document ...

An exploration of distributing union types within conditional type arrays in TypeScript

One interesting challenge I am facing involves a conditional type that utilizes a generic type T in order to determine an Array<T> type. For example: type X<T> = T extends string ? Array<T> : never; The issue arises when I input a union ...