function exampleFunction<T>(arg: T): void {
if (typeof arg === 'string') {
console.log('T is a string');
} else if (typeof arg === 'number') {
console.log('T is a number');
} else {
console.log('T is of another type');
}
}
export function JumpByObject(params: NewsListBean | JumpData) {
if (params instanceof NewsListBean) {
console.log('11111111111111');
}else if(params instanceof JumpData){
console.log('22222222222222');
}
}
可使用instanceof 判断某个对象是否是另一个对象的实例,typeof用于检测对象的类型,可参考如下代码: