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

栏目: 软件资讯 · 发布时间: 7年前

内容简介:TypeScript 3.3 发布了 RC 版本,3.3 是一个平滑的版本,不包含重大更改。 此版本的亮点包括: 改进了调用 union 类型的行为 当 TypeScript 具有 union 类型 A | B 时,允许访问 A 和 B 的交集属性。 interface ...

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 install -g typescript@rc

或者:


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Ruby on Rails社区网站开发

Ruby on Rails社区网站开发

布拉德伯纳 / 柳靖 / 2008-10 / 55.00元

《Ruby on Rails社区网站开发》全面探讨创建完整社区网站的开发过程。首先介绍开发一个内容简单的管理系统,之后逐渐添加新特性,以创建更完整的、使用Ruby on Rails 的Web 2.0 社区网站。还给出了开发和测试中的一些建议和提示,同时指导如何使网站更生动以及维护得更好。《Ruby on Rails社区网站开发》也探讨了如何与Flickr 、Google Maps 等其他平台集成,......一起来看看 《Ruby on Rails社区网站开发》 这本书的介绍吧!

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

在线进制转换器
在线进制转换器

各进制数互转换器

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具