ts3.3版本特性

19 篇文章 0 订阅

ts3.3版本特性

Improved behavior for calling union types

可以调用类型的联合类型的增强。

//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") //这里orange extends Fruit同时orange extends Color,但是f声明后不能使用
//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"'.

3.3的版本中可调用函数的联合类型,其参数位是两个函数参数位类型的交叉类型,正如

("apple" | "orange") & ("red" | "orange") ===> ("apple" & "red") | ("apple" & "orange") | ("orange" & "red") | ("orange" & "orange")

类似笛卡尔积形成的那种方式

A={a,b}, B={0,1,2} 返回一个 {(a, 0), (a, 1), (a, 2), (b, 0), (b, 1), (b, 2)}

这个提升只有在函数重载的时候才会生效

Incremental file watching for composite projects in--build --watch

这个功能我没怎么用过,我认为构建应该交给构建的工具做会更好。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值