TS2394

This overload signature is not compatible with its implementation signature.

Broken Code ❌

The implementation does not match all signatures:

function sum(a: number, b: number): number;
function sum(a: string, b: string): string;
function sum(a: number | string, b: number | string) {
  return `${parseInt(a + '', 10) + parseInt(b + '', 10)}`;
}

Fixed Code ✔️

To match the first function overload, we have to add code to our function body which can also return a number:

function sum(a: number, b: number): number;
function sum(a: string, b: string): string;
function sum(a: number | string, b: number | string) {
  if (typeof a === 'number' && typeof b === 'number') {
    return a + b;
  }
  return `${parseInt(a + '', 10) + parseInt(b + '', 10)}`;
}

Video Tutorial