TypeScript's string enums - “Type … is not assignable to type …”

后端 未结 9 2046
不思量自难忘°
不思量自难忘° 2020-12-10 23:45

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:

9条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-11 00:33

    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 *

提交回复
热议问题