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

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


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



I've got problem with building application at Visual Studio 2017. I'm using ASP.NET CORE 2 and Angular 6. After running application i'm getting errors at file output_ast.d.ts from node_modules:



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



and



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



Code with error:


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



My package.json


"name": "client-app",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"@angular/animations": "^6.0.0",
"@angular/common": "^6.0.0",
"@angular/compiler": "^6.0.0",
"@angular/core": "^6.0.0",
"@angular/forms": "^6.0.0",
"@angular/http": "^6.0.0",
"@angular/platform-browser": "^6.0.0",
"@angular/platform-browser-dynamic": "^6.0.0",
"@angular/router": "^6.0.0",
"core-js": "^2.5.4",
"rxjs": "^6.0.0",
"zone.js": "^0.8.26"
},
"devDependencies": {
"@angular/compiler-cli": "^6.0.0",
"@angular-devkit/build-angular": "~0.6.1",
"typescript": "~2.7.2",
"@angular/cli": "~6.0.1",
"@angular/language-service": "^6.0.0",
"@types/jasmine": "~2.8.6",
"@types/jasminewd2": "~2.0.3",
"@types/node": "~8.9.4",
"codelyzer": "~4.2.1",
"jasmine-core": "~2.99.1",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~1.7.1",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "~1.4.2",
"karma-jasmine": "~1.1.1",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~5.3.0",
"ts-node": "~5.0.1",
"tslint": "~5.9.1"
}
}



Application is made similar to this article https://www.codeproject.com/Articles/1245243/How-to-Create-an-App-with-Angular-and-ASP-NET-C
but angular app is in separated folder called ClientApp.
I've tryed different versions of ts and angular cli and nothing helps. What can I do with that error ?




4 Answers
4



In Visual Studio, check the settings in your project Properties->TypeScript Build section and make sure TypeScript Version is set to "Use latest available" or at least something fairly recent. I suspect it's currently set to something prior to when TypeScript supported string enums.





This is a helpful breadcrumb for me, thanks. See below.
– christok
Jun 16 at 15:21





This is great answer
– love prince
Jul 19 at 10:15



I experienced the exact same behavior and in appeared to be a TS version incompatibility issues. Instead of changing TypeScript version to "Use latest available" as suggested above, I was able to resolve by changing TypeScript version to 2.2.



To have a string enum, you only have to do the following


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



as per documentation





Still the same error. Maybe I asked wrong question. What should I do to build this app ?
– Jakubbb
May 27 at 16:34





If you've followed standards, ng build, or npm run build should work. Without the content of your package.json, without knowing how you created your app, I can't help you.
– Deblaton Jean-Philippe
May 27 at 17:09


ng build


npm run build





I've added package.json to main post and described how I created my app. Can you look at that ?
– Jakubbb
May 27 at 18:01



tldr; Upgrade the TypeScript compiler that Visual Studio is using.



Visual Studio 2017 is probably attempting to build the project using an older version of TypeScript than 2.4, when string initializers for enums was introduced: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-4.html.



There are 3 different TypeScript compilers to be aware of here:



To upgrade the TypeScript compiler that VS is using, go to the https://marketplace.visualstudio.com and search for the latest TypeScript extension. Install it, restart Visual Studio, then in the Project settings make sure the TypeScript build version is set to that new version. Now if you rebuild, the error should disappear.






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Arduino Mega cannot recieve any sketches, stk500_recv() programmer is not responding

Visual Studio Code: How to configure includePath for better IntelliSense results

C++ virtual function: Base class function is called instead of derived