I have a function that accepts a number or a string, and, if the type is string returns 'string' or if the type is number it returns number.
Code:
function stringOr1(v: number): number;
function stringOr1(v: string): string;
function stringOr1(v: number | string) {
if (typeof v == 'string') {
return 'string';
}
else {
return 1;
}
}
const s1 = stringOr1('1');
const s2 = stringOr1(1);
TS error:
This overload signature is not compatible with its implementation signature.
What am I doing wrong?