今天,微软在一篇博文中宣布了TypeScript 3.3 RC的普遍可用性。 此版本不包含任何重大或重大更改。
调用union类型时更好的行为
当有一个联合类型A | B,TypeScript现在允许用户访问A和B共有的所有属性。例如,成员的交集。 只有当已知每个联合类型中存在属性时,才可以从联合类型获取属性。 当每种类型只有一个具有相同参数的签名时,事情就会起作用。 这种限制太多,在某些方面存在错误。 因此,在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"'.
以上签名的参数“intersected”以创建新签名。当不可能的交叉点消失后,剩下的就是“orange”和“orange”,而“orange”就是“orange”。这并不是说没有限制。只有当联合中只有一种类型具有多个重载和泛型签名时,新行为才是活动的。forEach方法现在是可调用的,但是在noImplicitAny下可能存在一些问题。
在TypeScript 3.3中,-build模式的-watch标志也利用了增量文件监视功能。使用-build -watch可以大大加快构建速度。据报道,构建时间减少了50%以上。
更多信息
使用Visual Studio Code开发TypeScript http://www.linuxidc.com/Linux/2015-07/119456.htm
WebStorm下使用TypeScript http://www.linuxidc.com/Linux/2015-06/118853.htm
TypeScript 基本语法 http://www.linuxidc.com/Linux/2015-06/118852.htm
TypeScript 的详细介绍:请点这里
TypeScript 的下载地址:请点这里
Linux公社的RSS地址:https://www.linuxidc.com/rssFeed.aspx
本文永久更新链接地址:https://www.linuxidc.com/Linux/2019-01/156530.htm