How to use function with rest parameters (N number of parameters) in TypeScript

2 Answers

0 votes
function Test(...lang: string[]) {
    return lang.join(", ");
}

console.log(Test("TypeScript", "Java", "C++")); 

console.log(Test("Python"));


   

   
/*
   
run:
   
"TypeScript, Java, C++" 
"Python" 
  
*/

 



answered Oct 25, 2021 by avibootz
0 votes
function Test(x: number, ...lang: string[]) {
    return  x + " " + lang.join(", ");
}

console.log(Test(123, "TypeScript", "Java", "C++")); 

console.log(Test(837, "Python"));


   

   
/*
   
run:
   
"123 TypeScript, Java, C++" 
"837 Python"
  
*/

 



answered Oct 25, 2021 by avibootz
...