代码拉取完成,页面将自动刷新
完整的破坏性改动列表请到这里查看: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;
}
推荐:
在定义类成员时删除关键字后面的换行。通常来讲,要避免依赖于自动插入分号机制。
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。