Unexpected identifier in the interface

Within my main.ts file, I've included the following code snippet :

interface bodyInfos {
    height?: any;
    mass?: any;
}

const calculateBmi = (user: bodyInfos) => {
    return user.mass / ( user.height ** 2 );
};

let foo: bodyInfos;
let bar: bodyInfos;

// Foo
foo.height = 172;
foo.mass = 75;
// Bar
bar.height = 180;
bar.mass = 90;

console.log('foo BMI', calculateBmi(foo) );
console.log('bar BMI', calculateBmi(bar) );

Whenever I attempt to run the main.ts file using the command: node main.ts, an error pops up in the console displaying:

interface bodyInfos {
          ^^^^^^^^
SyntaxError: Unexpected identifier

I'm reaching out for your assistance, please.

Answer №1

Shoutout to @VLAZ for helping me figure this out,

So, what I ended up doing was compiling main.ts into main.js by running tsc main.ts and then executing the command node main.js on the newly compiled file - and it worked like a charm.

Just a quick note: I initially attempted to compile the file using ts-node but encountered a slew of errors in the console output, so that didn't go as planned.

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 TypeScript to chain observables in a service and then subscribing to them in the component at the end

Working with Platform - Angualar 2 + TypeScript + angularFire2 Within my user.service.ts file, I have implemented the following code to initiate an initial request to a firebase endpoint in order to fetch some path information. Subsequently, I aim to util ...

Using inertia-links within the storybook framework

Hey there, just wanted to share my experience with storybook - I'm really enjoying it so far! Currently, I'm facing a challenge while implementing it in my Laravel app with Inertia. I'm trying to render a navigation link component that make ...

Dynamically divide canvas screens based on fabricjs dropdown selection

I am attempting to implement split screens in fabric js, such as 1, 2, 4, 8, and 16. The screen should split based on the selection from the dropdown menu. Check out my current code where I have successfully uploaded images. If I click on the images, th ...

Issues with the proper functionality of the .ajax() method in Django

I'm currently facing an issue with my Ajax code while trying to interact with the database in order to edit model instances. I noticed that the first alert statement is functioning correctly, however, the subsequent alert statements are not working as ...

What is the best way to split a semicircular border radius in two equal parts?

Is there a way to halve the yellow line or remove it from above the red box, while keeping it below? Can this be achieved using just HTML and CSS, or is JavaScript necessary? * { margin: 0; padding: 0; box-sizing: border-box; } body { height: 1 ...

Module.exports causing keyword errors in eslint

Encountering some unusual errors from eslint CI regarding my jest.config.js file. 1:1 error Rule 'no-empty-label' has been replaced by: no-labels no-empty-label 1:1 error Rule 'no-reserved-keys' has been replaced ...

Is a finished callback needed for .on('xxx') event?

On my dashboard page, I am currently retrieving the top 25 comments and displaying them using the following code: fba.orderByChild('when').limitToLast(25).on('child_added', function (d, c) { stuff }); However, the function is called f ...

Having issues with jQuery's .text() method not functioning as expected on XML elements

Looking at the javascript code below: function getAdminMessageFromXML(xml) { alert('xml: ' + xml); alert("Text of admin message: " + $(xml).find('dataModelResponse').find('adminMessage').text()); return $(xml).fin ...

Guide on updating BgImage dynamically through JavaScript

I've been exploring a way to dynamically update the background image of an HTML document using JavaScript. While I am familiar with hardcoding the links, I'm interested in loading it from a variable URL that I specify. Here is what currently work ...

The correlation among the event loop, libuv, and the V8 engine

Exploring the intricacies of Node.js architecture has led me to several thought-provoking questions. Is the event loop a component of libuv or v8? Does the event queue operate within the event loop? And if so, is it generated by libuv, v8 engine, or th ...

Steps for deactivating tab stops on the primary webpage in the presence of a snackbar

On my web page, there are multiple drop-down menus, input fields, and buttons that can be interacted with using both the tab key and mouse. After entering certain data, I trigger a snackbar (source: https://www.w3schools.com/howto/howto_js_snackbar.asp) t ...

Discovering if a consistent value is present in every row of an array list can be achieved using Angular

In my array list, I have a collection of values structured as follows: "data": { "input": [ { "weight": 'KG', "Amt": 40 }, { "weight": 'KG', "Amt": 20.25 }, { "weight": 'KG', "Amt": 10.30 } ] } How ...

What is the best way to retrieve ember model relation properties within routes and controllers?

Currently using ember 2.7.0, I am facing an issue while setting up my ember app with a currentUser.organization derived from the authenticated token. Although I can successfully resolve the currentUser, I am encountering difficulties in resolving the prope ...

Certain crucial happenings inhibit the ability of others to occur

Hey there! Want to check out the live application I'm currently working on? Simply click this link: turbo_synth This project is being developed using VueJS, however, the issue I've encountered does not seem to be related to Vue at all. The prob ...

Angular - What is the best way to simulate an HTTP request in testing?

Although I currently have a basic code that triggers an actual HTTP request : @Component({ selector: 'my-app', template: ` <div> <h2>Hello {{person?.id}}</h2> </div> `, }) export class App { name:str ...

Is it possible to initialize multiple Observables/Promises synchronously in ngOnInit()?

I am relatively new to Angular/Typescript and facing a challenge. In my ngOnInit(), I am trying to fetch settings from my backend using a GET request. After that, I need to subscribe to an observable. The observable updates the widgets' content over t ...

Transform HTML elements within an *ngFor iteration based on a specific variable in Angular 4

In my current project using Angular 4, I am faced with the task of dynamically modifying HTML tags within an *ngFor loop based on a variable. Here is the code snippet that represents my approach: <mat-card-content *ngFor="let question of questionGrou ...

Issue with rendering JavaScript in Django template

I encountered an issue with my template that includes JavaScript. For example: <script>var i = /{{([a-z]*)}}/gi;</script> Typically, the template interpreter tries to interpret anything inside double curly braces {{}} as a variable. I am now ...

In JavaScript, it is not possible to retrieve the maximum or minimum value of an array

Hey there! I'm having some trouble finding the minimum and maximum values in an array. Can you help me figure out what's going on with my code? var repeated, studentsArray = [], marksArray = []; while (repeated !== 'n' && r ...

What is the process for transforming JSON into a different format?

Currently, I have a JSON array structured as follows: var data = { report: [ { Name: "Nitin", comment: [ { count: 0, mName: "Feb" }, ...