Typescript中方法重载的实现
function getInfo(name:string):string;
function getInfo(age:number):string;
function getInfo(str:any):any{
if (typeof str==‘string‘) {
return ‘我叫---‘+str
}
if (typeof str==‘number‘) {
return ‘我的年龄---‘+str
}
}
console.log(getInfo(‘张三‘))
console.log(getInfo(18))
运行结果:

原文:https://www.cnblogs.com/malong1992/p/13380876.html