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

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

内容简介: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

或者:


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

查看所有标签

猜你喜欢:

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

MySQL权威指南

MySQL权威指南

Randy Jay Yarger / 林琪、朱涛江 / 中国电力出版社 / 2003-11-1 / 49.00元

为一种开源数据库,MySQL已经成为最流行的服务器软件包之一。开发人员在其数据库引擎中提供了丰富的特性(只需很少的内存和CPU支持)。 因此,众多Linux和Unix服务器(以及一些Windows服务器)都采用MySQL作为其数据库引擎。由于MySQL作为Web站点后端时速度特别快而且相当方便,所有在目前流行的一个词LAMP(表示Linux、Apache、MySQL和Perl、Python或......一起来看看 《MySQL权威指南》 这本书的介绍吧!

HTML 编码/解码
HTML 编码/解码

HTML 编码/解码

MD5 加密
MD5 加密

MD5 加密工具