- 0133技术站
- 联系QQ:18840023
- QQ交流群
- 微信公众号
完整的破坏性改动列表请到这里查看:breaking change issues。
this
中推断类型发生了变化在类里,this
值的类型将被推断成this
类型。
这意味着随后使用原始类型赋值时可能会发生错误。
例子:
class Fighter { /** @returns the winner of the fight. */ fight(opponent: Fighter) { let theVeryBest = this; if (Math.rand() < 0.5) { theVeryBest = opponent; // error } return theVeryBest } }
推荐:
添加类型注解:
class Fighter { /** @returns the winner of the fight. */ fight(opponent: Fighter) { let theVeryBest: Fighter = this; if (Math.rand() < 0.5) { theVeryBest = opponent; // no error } return theVeryBest } }
关键字abstract,public,protected
和private
是ECMAScript 3里的保留关键字并适用于自动插入分号机制。
之前,在这些关键字出现的行尾,TypeScript是不会插入分号的。
现在,这已经被改正了,在上例中abstract class D
不再能够正确地继承C
了,而是声明了一个m
方法和一个额外的属性abstract
。
注意,async
和declare
已经能够正确自动插入分号了。
例子:
abstract class C { abstract m(): number; } abstract class D extends C { abstract m(): number; }
推荐:
在定义类成员时删除关键字后面的换行。通常来讲,要避免依赖于自动插入分号机制。
推荐手册