面试题答案
一键面试function calculate(a: number, b: number): number;
function calculate(a: string, b: string): number;
function calculate(a: string | number, b: string | number): number {
if (typeof a ==='string' && typeof b ==='string') {
return parseInt(a) + parseInt(b);
} else if (typeof a === 'number' && typeof b === 'number') {
return a + b;
}
return NaN;
}