Can I use latest stable TypeScript or should I sti

2019-05-27 04:16发布

问题:

I wasn't able to find any official recommendation about whether or not upgrade the TypeScript version using the latest stable version available.

The npm version is automatically set in package.json by AngularCLI when creating a new project. It currently is:

"typescript": "~2.4.2"

which means latest 2.4.x version. I was wondering if it would be possible to use the latest stable TypeScript version (and what would be the implications), for example 2.5.x.

Is there a specific reason for setting ~2.4.2 and not "^2.4.2 (which means latest 2.x.x version).

回答1:

Angular cli may not always support the latest version of TypeScript. There is some issues and PR's related to that:
- Support TypeScript 2.4+
- Typescript 2.4 support
- feat(@angular/cli): support TypeScript 2.4

Also bare in mind that the latest TypeScript version might not be compatible with your Angular version.

If you want to jump to a new/latest TypeScript version - it is at your own risk. Once you do so you have to make sure that it is not breaks anything like tests(ng t), prod build(ng build --prod), etc.

If you stick to the default cli TypeScript version you - are safe.

UPDATE 09 Sept 2017: For anyone who care about using the cli with the latest TypeScript checkout this recent github issue and this particular comment as there was a TypeScript version warning logic introduced in the latest cli 1.4. Here is what it is based on(angular cli team recommendation):

 const versionCombos = [
      { compiler: '>=2.3.1 <3.0.0', typescript: '>=2.0.2 <2.3.0' },
      { compiler: '>=4.0.0 <5.0.0', typescript: '>=2.1.0 <2.4.0' },
      { compiler: '>=5.0.0 <6.0.0', typescript: '>=2.4.0 <2.6.0' }
    ];


回答2:

Yes, you can change/ update but make sure you follow every release for support and updates. Every release it will change.

I use the very latest typescript version and never faced a problem so far.

UPDATE:

Since Angular 1.4 angular-cli reports the required typescript version while serve, build and version check

Example:

@angular/compiler-cli@4.3.6 requires typescript@'>=2.1.0 <2.4.0' but 2.4.2 was found instead. Using this version can result in undefined behaviour and difficult to debug problems.

Please run the following command to install a compatible version of TypeScript.

npm install typescript@'>=2.1.0 <2.4.0'

To disable this warning run "ng set --global warnings.typescriptMismatch=false".



回答3:

Type the following command in your Terminal or Command prompt when you get this Message (Please run the following command to install a compatible version of TypeScript.) (npm install typescript@'>=2.1.0 <2.4.0')

npm install -g typescript