1.方法的重载:
function: getInfo(name:string):string;
function:getInfo(age:number):number;
function:getInfo(str:any):any{
if(typeof str === string){
console.log("这是string");
}else if(typeof str === string){
console.log("这是number");
}else{
console.log("这是其他类型")
}
}
网友评论