TypeScript 3.3 RC 已經釋出
今天,微軟在一篇博文中 宣佈了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開發TypeScripthttp://www.linuxidc.com/Linux/2015-07/119456.htm
WebStorm下使用TypeScripthttp://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