面试题答案
一键面试function combine<T extends string | number>(a: T, b: T): T extends string ? string : number {
if (typeof a === 'string' && typeof b === 'string') {
return (a + b) as T extends string ? string : number;
} else if (typeof a === 'number' && typeof b === 'number') {
return (a + b) as T extends string ? string : number;
}
throw new Error('参数类型不匹配');
}