How to use function overloading in TypeScript

1 Answer

0 votes
function add(a:string, b:string):string;

function add(a:number, b:number): number;

function add(a: any, b:any): any {
    return a + b;
}


console.log(add("TypeScript ", "C++")); 

console.log(add(3, 18)); 



   

   
/*
   
run:
   
"TypeScript C++" 
21 
  
*/

 

 



answered Oct 24, 2021 by avibootz

Related questions

...