我可以使用最新的稳定 TypeScript 还是应该坚持使用 AngularCLI 附带的版本? [英] Can I use latest stable TypeScript or should I stick with the version shipped with AngularCLI?

查看:25
本文介绍了我可以使用最新的稳定 TypeScript 还是应该坚持使用 AngularCLI 附带的版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找不到任何关于是否使用可用的最新稳定版本升级 TypeScript 版本的官方建议.

在创建新项目时,AngularCLI 会在 package.json 中自动设置 npm 版本.目前是:

"typescript": "~2.4.2"

表示最新的 2.4.x 版本.我想知道是否可以使用最新的稳定 TypeScript 版本(以及会产生什么影响),例如 2.5.x.

设置 ~2.4.2 而不是 "^2.4.2 是否有特定原因(这意味着最新的 2.xx 版本).

解决方案

2021 年更新:
查看此答案 是是否有 Angular/Angular-CLI 和 Node.js 的兼容性列表?


原始答案:
Angular cli 可能并不总是支持最新版本的 TypeScript.有一些问题和 PR 与此相关:

还要记住,最新的 TypeScript 版本可能与您的 Angular 版本不兼容.

如果您想跳转到新的/最新的 TypeScript 版本 - 风险自负.一旦你这样做了,你必须确保它不会破坏任何东西,比如测试(ng t)、prod build(ng build --prod)等.><块引用>

如果您坚持使用默认的 cli TypeScript 版本,您 - 是安全的.

2017 年 9 月 9 日更新:对于任何关心使用带有最新 TypeScript 的 cli 的人,请查看最近的 github 问题 和这个特殊的 评论 因为在最新的 cli 1.4 中引入了 TypeScript 版本警告逻辑.这里是a> 它基于(angular cli 团队推荐):

 const versionCombos = [{ 编译器:'>=2.3.1 <3.0.0',打字稿:'>=2.0.2 <2.3.0' },{ 编译器:'>=4.0.0 <5.0.0',打字稿:'>=2.1.0 <2.4.0' },{ 编译器:'>=5.0.0 <6.0.0',打字稿:'>=2.4.0 <2.6.0' }];

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).

解决方案

UPDATE 2021:
Checkout this answer
Is there a compatibility list for Angular / Angular-CLI and Node.js?


ORIGINAL ANSWER:
Angular cli may not always support the latest version of TypeScript. There is some issues and PR's related to that:

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' }
    ];

这篇关于我可以使用最新的稳定 TypeScript 还是应该坚持使用 AngularCLI 附带的版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆