从 JavaScript 迁移到 TypeScript·续1
这就产生了我们上面提到的错误 - 如果我们错误地拼写了getDistance并不会得到一个错误。 正因此,TypeScript有noImplicitThis选项。 当设置了它,TypeScript会产生一个错误当没有明确指定类型(或通过类型推断)的this被使用时。 解决的方法是在接口或函数上使用指定了类型的this参数:
Point.prototype.distanceFromOrigin = function(this: Point, point: Point) { return this.getDistance({ x: 0, y: 0});}
