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
这个功能我没怎么用过,我认为构建应该交给构建的工具做会更好。