Typescript方法重载实现系列二
function getInfo(name:string):string; function getInfo(name:string,age:number):string; function getInfo(name:any,age?:any):any{ if (age) { return '我叫---'+name+'我的年龄是'+age } else{ return '我是'+name } } console.log(getInfo("李四")) console.log(getInfo("李四",20))
运行结果: