Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

TS2394: This overload signature is not compatible with its implementation signature

I am fairly new to TS and learning function overloading. Somehow I am making a mistake that I can’t seem to identify . The snippet is

function parseCoordinate(obj : Coordinate): Coordinate; function
parseCoordinate(str : String): Coordinate; function parseCoordinate(x:
number, y: number): Coordinate; function parseCoordinate(arg1:
unknown, arg2: unknown): Coordinate {
let coord: Coordinate = {
x: 0,
y: 0
}

if (typeof arg1 === 'object') {
    coord = {
        ...(arg1 as Coordinate)
    }
} else {
    coord = {
        x: arg1 as number,
        y: arg1 as number
    }
}
return coord; }

I am told the titualr error for first line

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

the reason is your implementation requires 2 parameters

parseCoordinate(arg1: unknown, arg2: unknown)

and 1 param overloads aren’t compatible with 2 argument calls. to fix it make 2nd parameter optional by using ?

parseCoordinate(arg1: unknown, arg2?: unknown)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading