TypeScript学习
2019-07-05 本文已影响5人
二营长家的张大炮
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("这是其他类型")
}
}