TypeScript 1.7
从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
}
}类成员修饰符后面会自动插入分号
Last updated