I have this interface:
interface IPoint {
getDist(): string;
getDist(x: number): any;
}
and I need a class to implement it, but I can’t get the correct syntax to implement the getDist () method in the class.
class Point implements IPoint {
constructor (public x: number, public y: number) { }
pointMethod() { }
getDist() {
Math.sqrt(this.x * this.x + this.y * this.y);
}
static origin = new Point(0, 0);
}
He says:
The Point class declares the IPoint interface, but does not implement it: The 'getDist' property types of the 'Point' and 'IPoint' types are incompatible: call signatures of the types' () => void 'and' {(): string; (x: number): any; } 'incompatible
What is the right way to do this?
thank
source
share