Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeScript's string enums - "Type ... is not assignable to type ..."

I have recently upgraded the version of TypeScript from 2.3.4 to 2.4.0 hoping to use the string enums. To my dismay, however, I have been greeted with the error messages:

Severity  Code    Description Project File    Line    Suppression State Error TS2322  Type '"E"' is not assignable to type 'StepType'.   ClientApp (tsconfig project)  Z:\SMART\Smart\Smart\ClientApp\app\models\process.model.ts  17  Active Error TS2322  Type '"S"' is not assignable to type 'StepType'.   ClientApp (tsconfig project)  Z:\SMART\Smart\Smart\ClientApp\app\models\process.model.ts  14  Active Error TS2322  Type '"A"' is not assignable to type 'StepType'.   ClientApp (tsconfig project)  Z:\SMART\Smart\Smart\ClientApp\app\models\process.model.ts  15  Active Error TS2322  Type '"D"' is not assignable to type 'StepType'.   ClientApp (tsconfig project)  Z:\SMART\Smart\Smart\ClientApp\app\models\process.model.ts  16  Active 

The error messages apply to the following code snippet (with the line numbers):

13. export enum StepType { 14.    Start = 'S', 15.    Activity = 'A', 16.    Decision = 'D', 17.    End = 'E' 18. } 

I am using Visual Studio 2017 which claims TypeScript 2.4.0 is installed:

enter image description here

I searched through TypeScript's issues, but without luck. Does anybody know how to fix it?

like image 413
Dawid O Avatar asked Jul 19 '17 13:07

Dawid O


1 Answers

This is because typescript version.

Open command prompt or terminal. then run these commands.

Check TypeScript version

tsc -v 

should be higher than 2.4

if not.

install latest version of typescript globally

npm install typescript -g 

Open your package.json file of the project and change typescript version like this with newly installed version

"typescript": "~2.6.1" 

Then delete node_modules folder

Clean cache using

npm cache clean 

Finally run

npm install 

*Note that: You can update npm using npm update but it is not sure that the typescript version will be updated *

like image 197
Chanaka Fernando Avatar answered Sep 24 '22 00:09

Chanaka Fernando