How to use the spread operator to pass an array of arguments to a function in TypeScript

1 Answer

0 votes
function PrintAll(a: number, b: string, c: number, d: number) {
    console.log(a, b, c, d);
}

let tpl: [number, string, number, number];

tpl = [1, 'a', 3, 4];

PrintAll(...tpl); 

  
  
/*
run:
  
1 a 3 4
  
*/

 



answered Jan 24, 2025 by avibootz
...