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

后端 未结 9 2056
不思量自难忘°
不思量自难忘° 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:26

    I had the same issues for my Angular2 project. I needed to update the Typescript (TS) library in my Angular2 project.

    1) Inside your package.json, add this to the "devDependencies" section:

    "ts-node": "~3.2.0",
    "tslint": "~5.7.0",
    "typescript": "~2.4.2"
    

    So mine looks like:

      "devDependencies": {
        "@angular/compiler-cli": "^2.3.1",
        "@types/jasmine": "2.5.38",
        "@types/node": "^6.0.42",
        "angular-cli": "1.0.0-beta.28.3",
        "codelyzer": "~2.0.0-beta.1",
        "jasmine-core": "2.5.2",
        "jasmine-spec-reporter": "2.5.0",
        "karma": "1.2.0",
        "karma-chrome-launcher": "^2.0.0",
        "karma-cli": "^1.0.1",
        "karma-jasmine": "^1.0.2",
        "karma-remap-istanbul": "^0.2.1",
        "protractor": "~4.0.13",
        "ts-node": "~3.2.0",
        "tslint": "~5.7.0",
        "typescript": "~2.4.2"
      }
    

    2) Delete "node_modules" package and "package-lock.json" file from your project.

    3) Do "npm install" on your command line in order to install all the new TS libraries.

提交回复
热议问题