(TS) When defining a 'const' enum, the member initializer must be a constant expression

I'm encountering an issue while building my application in Visual Studio 2017. The project is using ASP.NET CORE 2 and Angular 6. Once I run the application, errors are popping up in the file output_ast.d.ts within the node_modules directory:

(TS) In 'const' enum declarations member initializer must be constant expression.

and

Build:In 'const' enum declarations member initializer must be constant expression.

The code causing the error:

export declare const enum JSDocTagName {
    Desc = "desc",
    Id = "id",
    Meaning = "meaning",
}

Here's a snippet from my package.json:

  "name": "client-app",
  "version": "0.0.0",
  ... (package.json content)

The structure of my application is similar to the one explained in this article https://www.codeproject.com/Articles/1245243/How-to-Create-an-App-with-Angular-and-ASP-NET-C, however, the Angular app is located in a separate folder called ClientApp. I've tried varying versions of TypeScript and Angular CLI without success. Any suggestions on how to resolve this error?

Answer №1

When using Visual Studio, it is important to review the configuration settings within your project's Properties->TypeScript Build section. Ensure that the TypeScript Version is set to either "Use latest available" or a version that is relatively current. It is likely that the current setting predates the addition of string enums support in TypeScript.

Answer №2

Encountered a similar issue myself, which seemed to stem from compatibility problems with the TypeScript version. Rather than updating to the "Latest available" version as advised earlier, I managed to fix it by downgrading my TypeScript to 2.2.

Answer №3

Creating a string enum is simple, just follow these steps:

export enum JSDocTagName {
    Desc = "desc",
    Id = "id",
    Meaning = "meaning",
}

For more information, refer to the official documentation

Answer №4

In summary: It's recommended to update the TypeScript compiler being used by Visual Studio.

Visual Studio 2017 may be trying to compile the project with an outdated version of TypeScript prior to 2.4, which introduced string initializers for enums. More information can be found at this link.

It is important to note that there are three different TypeScript compilers in play here:

  • Angular CLI: utilizes the local project node_modules/typescript folder
  • NPM: relies on the globally installed TS compiler (%AppData%/npm/Roaming on Windows)
  • Visual Studio: uses the TS compiler located in C:\Program Files (x86)\Microsoft SDKs\TypeScript

To upgrade the TypeScript compiler in use by Visual Studio, visit the Visual Studio Marketplace website and search for the latest TypeScript extension. Once installed, restart Visual Studio and ensure that the TypeScript build version is set to the updated one in Project settings. After rebuilding, any errors should no longer persist.

Answer №5

According to @ben-barreth, it seems like I am facing the same issue as well. It appears that VS Code's tsc is using a version lower than 2. Instead of updating the Visual Studio Code plugin, a more efficient solution would be to utilize the npm package by specifying the path to tsc explicitly as ./node_modules/.bin/tsc.

$ ./node_modules/.bin/tsc --version
Version 4.3.2

$ tsc --version
message TS6029: Version 1.5.3

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

Having trouble accessing the application on localhost

I'm diving into the world of Docker! I'm looking to build a personalized docker image for an Angular application using a Dockerfile. I've successfully created the image and got the container up and running, but unfortunately, I'm unable ...

Error encountered: ASP.NET Sys.WebForms.PageRequestManagerParseErrorException

I've inherited a project from a colleague at work I'm trying to troubleshoot an error that keeps happening Every time this line of code is executed, an error occurs: Response.Redirect("ViewPositions.aspx?empid=1"); Interestingly, the ViewPosi ...

Tips for handling callback responses from API POST requests in Node.js

I have integrated the following API Function into my project: The backend is built using NodeJS and the frontend with Angular. I am struggling to understand how the Callback in the function's POST request works. It seems to require a domain setup an ...

Recursive rendering of tree components in React

I am facing a challenge in rendering tree items recursively using React. I have been struggling to achieve the desired outcome as calling treeRender(children) seems to alter the data structure when a folder is encountered for the first time. I am curious a ...

Analyzing information from a single table through a Select Query on ASP platform

Dear members, I have data spanning two years in a single SQL table and have created a gridview to display this data for one month using a Select query command as follows: <asp:SqlDataSource ID="SqlDataSource15" runat="server" ConnectionString= ...

Typescript - any of the types imported from a module

Currently, my code looks like this: import * as Types from '../schema/types'; and I'm looking to achieve something along the lines of: let a: Types; This would signify that a should be one of the various types exported from the file types. ...

What steps should I take to generate a compiler error when a variable is not of the type "never"?

Imagine having a set of conditions with different possible values and wanting to cover each potential case. In the event of adding a new condition in the future but forgetting to handle it, it is important to have an error detection mechanism—ideally cat ...

Pass the DateTime object from ASP.NET to angularjs as a structured data type instead of converting it to a

I'm encountering an issue where I am sending a complex object from my ASP.NET backend to the AngularJS frontend. This object includes a DateTime property and a list of objects, each with their own DateTime property. These properties are all sent as st ...

What is the best approach for resolving this asynchronous task sequencing issue in JavaScript?

Below is a code snippet where tasks are defined as an object and the function definition should ensure the expected output is met. Let tasks = { ‘a’: { job: function(finish){ setTimeout(() => { ...

The Angular CDK Dialog fails to display properly when set to a static, fixed, or absolute layout

When utilizing Angular CDK 14.2.1 with the Dialog module from '@angular/cdk/dialog', I am experiencing an issue where the dialog does not display as a native modal on top of the UI. Instead, it appears within the HTML flow, rendering downstream o ...

Effective strategies for managing form submissions with React and Typescript

As I dive into refactoring my code to TypeScript, especially as I am still getting accustomed to it, I find myself pondering about the HTML element types with React events. This has led me to rethink how I approach form creation and submission event handli ...

Getting a list of the stack resources available in cloudformation using TypeScript

My team is developing an application that will deploy multiple stacks to AWS. One of these stacks is called SuperStar, and it can only exist once per AWS account. I am currently exploring how our TypeScript CDK can retrieve a list of stacks from CloudFor ...

Combining two elements in Angular 2

I am looking to find the intersection of two objects. My goal is to compare these objects and if they have matching values on corresponding keys, then I want to add them to a new object. obj1 = { "Projects": [ "test" ], "Companies": [ "facebook", "google ...

What are some strategies for locally developing Angular 7 libraries that have dependencies on one another? (Troubleshooting npm linking)

I am managing two Angular library NPM packages: A contains basic components A-BC includes components that enhance the ones in A, with additional features to interact with the BC library Some components in A-BC are imported from A like import { MyThing } ...

Is it possible to omit certain fields when using the select function in MikroORM?

When working with nested populate queries in MikroORM with MySQL, I am faced with the challenge of selecting 100 fields while wanting to exclude around 20 fields. It would make more sense to leave out those 20 fields, similar to using db.find().select("- ...

Difficulty transferring cookie/session between Express backend and React frontend

I'm encountering an issue with retrieving a session/cookie from an express backend to a react frontend. Front end: async function submitData() { await axios.post('http://127.0.0.1:8082/api/login', { credentials: 'include&ap ...

Consolidate multiple generic items into a single entry

In my current project, I am structuring the types for a complex javascript module. One of the requirements is to handle multiple types using generics, as shown in the snippet below: export interface ModelState< FetchListPayload, FetchListR ...

Tabcontainer in ajax not displaying tabs correctly in Internet Explorer 8

Currently, I am utilizing an AJAX tab container inside an update panel (along with a ToolScriptManager placed in the master pages) to display two tab controls. Interestingly, the tabs are rendering without any issues in Firefox, however, they are throwing ...

Transitioning Ionic 2 to Typescript 2.0 Release Candidate

My current setup involves using Ionic 2.0.0-beta.37 with typescript 1.8.x. I am trying to integrate D3 version 4 into my project, but the typings from d3-v4-definitelytyped are for Typescript 2.x. This mismatch is causing compile errors, and after reaching ...

Sorting data in an Angular JavaScript table by column filters for a combined outcome

I currently have an Angular ngx-datatable that lacks support for filtering by column. My goal is to implement an input filter for each column (which can be strings, multiple choices, etc.) and then merge all these individual filters into a single one. This ...