2KB项目,专业的源码交易网站 帮助 收藏 每日签到

TypeScript 3.3 RC 发布,增量构建,时间缩短超一半

  • 时间:2019-01-26 21:57 编辑:2KB 来源:2KB.COM 阅读:467
  • 扫一扫,手机访问
  • 分享
摘要: TypeScript 3.3 发布了 RC 版本,3.3 是一个平滑的版本,不包含重大更改。此版本的亮点包括:改进了调用 union 类型的行为当 TypeScript 具有 union 类型 A | B 时,允许访问 A 和 B 的交集属性。interface A&

TypeScript 3.3 发布了 RC 版本,3.3 是一个平滑的版本,不包含重大更改。

此版本的亮点包括:

改进了调用 union 类型的行为

当 TypeScript 具有 union 类型 A | B 时,允许访问 A 和 B 的交集属性。

interface A {
    aProp: string;
    commonProp: string;
}

interface B {
    bProp: number;
    commonProp: number
}

type Union = A | B;

declare let x: Union;

x.aProp; // error - 'B' doesn't have the property 'aProp'
x.bProp; // error - 'A' doesn't have the property 'bProp'
x.commonProp; // okay! Both 'A' and 'B' have a property named `commonProp`.

很显然,只有当 A 和 B 中都有某一个属性时,它才可以被调用。

但是把这个场景扩展到处理属性类型的时候,事情就不一样了:

type CallableA = (x: boolean) => string;
type CallableB = (x: boolean) => number;

type CallableUnion = CallableA | CallableB;

declare let f: CallableUnion;

let x = f(true); // Okay! Returns a 'string | number'.

union 中 A 和 B 共有的属性它们的类型不同,再极端一点:

type Fruit = "apple" | "orange";
type Color = "red" | "orange";

type FruitEater = (fruit: Fruit) => number;     // eats and ranks the fruit
type ColorConsumer = (color: Color) => string;  // consumes and describes the colors

declare let f: FruitEater | ColorConsumer;

// Cannot invoke an expression whose type lacks a call signature.
//   Type 'FruitEater | ColorConsumer' has no compatible call signatures.ts(2349)
f("orange");

TypeScript 3.3 中,这不再会产生错误:

type Fruit = "apple" | "orange";
type Color = "red" | "orange";

type FruitEater = (fruit: Fruit) => number;     // eats and ranks the fruit
type ColorConsumer = (color: Color) => string;  // consumes and describes the colors

declare let f: FruitEater | ColorConsumer;

f("orange"); // It works! Returns a 'number | string'.

f("apple");  // error - Argument of type '"apple"' is not assignable to parameter of type '"orange"'.

f("red");    // error - Argument of type '"red"' is not assignable to parameter of type '"orange"'.

--build 模式下 --watch 复合项目的增量文件

TypeScript 3.0 引入了一个用于构建称为“复合项目”的构建新功能,它可以确保用户将大型项目拆分为更小的部分,从而快速构建并保留项目结构,而不会影响现有的 TypeScript 体验。TypeScript 可以使用 --build 模式仅重新编译项目和依赖项集。

去年团队通过新的增量“builder” API 发布了优化的 --watch 模式,该模式仅重新检查已更改的文件或其依赖性可能影响类型检查的文件。

这两种模式,一个作用于项目间,一个作用于项目内。但是在使用 --build --watch 进行复合项目构建时,一个项目中的更新将强制完整构建整个项目,而不是确定该项目中的哪些文件受到影响。

TypeScript 3.3 中改进了这一点,现在 --build 模式也可以利用 --watch 只确定增量文件是否受影响的功能。这意味着在 --build --watch 模式下可以更快地进行构建。在测试中,此功能使得原始 --build --watch 构建时间缩短了 50% 到 75%。

详情查看发布公告

通过 NuGet,或使用如下的 npm 命令获取新版本:

npm install -g typescript@rc

或者:


2KB项目(www.2kb.com,源码交易平台),提供担保交易、源码交易、虚拟商品、在家创业、在线创业、任务交易、网站设计、软件设计、网络兼职、站长交易、域名交易、链接买卖、网站交易、广告买卖、站长培训、建站美工等服务

  • 全部评论(0)
资讯详情页最新发布上方横幅
最新发布的资讯信息
【计算机/互联网|】Nginx出现502错误(2020-01-20 21:02)
【计算机/互联网|】网站运营全智能软手V0.1版发布(2020-01-20 12:16)
【计算机/互联网|】淘宝这是怎么了?(2020-01-19 19:15)
【行业动态|】谷歌关闭小米智能摄像头,因为窃听器显示了陌生人家中的照片(2020-01-15 09:42)
【行业动态|】据报道谷歌新闻终止了数字杂志,退还主动订阅(2020-01-15 09:39)
【行业动态|】康佳将OLED电视带到美国与LG和索尼竞争(2020-01-15 09:38)
【行业动态|】2020年最佳AV接收机(2020-01-15 09:35)
【行业动态|】2020年最佳流媒体设备:Roku,Apple TV,Firebar,Chromecast等(2020-01-15 09:31)
【行业动态|】CES 2020预览:更多的流媒体服务和订阅即将到来(2020-01-08 21:41)
【行业动态|】从埃隆·马斯克到杰夫·贝佐斯,这30位人物定义了2010年代(2020-01-01 15:14)
联系我们

Q Q: 7090832

电话:400-0011-990

邮箱:7090832@qq.com

时间:9:00-23:00

联系客服
商家入住 服务咨询 投拆建议 联系客服
0577-67068160
手机版

扫一扫进手机版
返回顶部