随笔-生活工作点滴

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("这是其他类型")
}
}
上一篇 下一篇

猜你喜欢

热点阅读