TypeScript Rest Arguments Last Updated : 23 Jul, 2024 Comments Improve Suggest changes Like Article Like Report TypeScript rest arguments use the spread operator (...) to capture a variable number of function arguments into an array. This allows for flexible operations like merging, concatenating, or processing multiple inputs dynamically within a single function.Syntaxfunction function_name(...rest: type[]) { // Type of the is the type of the array. }Example 1: Sum of Integer ArgumentsIn this example, we will calculate the sum of integer arguments passed to a function using the rest parameter syntax. JavaScript function getSum(...numbers: number[]): number { let sum = 0; numbers.forEach((num) => sum += num); return sum; } // Function call console.log(getSum(10, 50, 30)); console.log(getSum(-50, 50, -10, 5)); Output:90-5Example 2: Concatenating StringsIn this example, we will concatenate several strings passed to a function as arguments JavaScript let generateGreeting = ( greeting: string, ...names: string[] ) : string => { return greeting + " " + names.join(", ") + "!"; } // Function call console.log( generateGreeting("Hello ", "GeeksforGeeks ", "ABCD ", "Apple") ); Output:Hello GeeksforGeeks , ABCD , Apple!ConclusionTypeScript rest arguments provide a flexible way to handle functions that can accept a variable number of arguments. By using the spread operator ..., you can capture these arguments into an array, allowing for operations such as summing integers or concatenating strings. This feature enhances the capability to write more dynamic and versatile functions in TypeScript. Comment More infoAdvertise with us Next Article TypeScript Rest Arguments 21mcsrltd Follow Improve Article Tags : JavaScript Web Technologies Geeks Premier League TypeScript Geeks Premier League 2023 +1 More Similar Reads Rest Parameters in TypeScript Rest parameters in TypeScript enable functions to handle an unlimited number of arguments by grouping them into an array. They are defined using ... and must be the last parameter.Allow flexible and dynamic input handling in functions.Simplify working with multiple arguments without specifying them 3 min read TypeScript Rest Parameters and Arguments TypeScript Rest Parameters allow functions to accept an indefinite number of arguments of the same type, collecting them into an array. Arguments refer to the actual values passed to a function when it's invoked, while Rest Parameters provide a way to handle multiple arguments as an array within the 2 min read TypeScript Specifying Type Arguments TypeScript is a powerful statically typed superset of JavaScript that allows you to define and enforce types in your code. One of the key features of TypeScript is the ability to specify type arguments when working with generic functions and classes. This article will provide a comprehensive guide o 3 min read TypeScript Custom Errors in RESTful API In this article, we will explore the importance of using custom error handling in TypeScript for RESTful APIs. We will begin by highlighting the problem statement, followed by demonstrating the problem with code examples and error outputs. Finally, we will present a solution approach using custom er 5 min read What are Generics in TypeScript ? In this article, we will try to understand all the facts as well as the details associated with Generics in TypeScript along with some coding examples. Generics in TypeScript: Whenever any program or code is written or executed, one major thing one always takes care of which is nothing but making re 3 min read Like