TypeScript Rest Parameters and Arguments Last Updated : 28 Apr, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report 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 function. Rest Parameters A rest parameter allows us to pass zero or any number of arguments of the specified type to a function. In the function definition where we specify function parameters rest of the parameters should always come at last or the typescript compiler will raise errors. Rest Parameter allows us to accept zero or more arguments of the specified type.A function (or a method) has only one rest parameter.This parameter appears at last in the function’s specified parameter list.Since here it is TypeScript being into the picture, the type of rest parameter is of an Array type (further the array could be string data type or number data type or anything).Syntaxfunction function_name (...rest_parameter_name : type[]) { }Parametersfunction_name: Function's identifier, used for calling and referencing the function within your code....rest_parameter_name: Collects multiple arguments into an array named rest_parameter_name.type[]: Specifies the expected data type for elements stored in the rest_parameter_name array. Example: In this example, we will get the sum of arguments of integers that are passed in a function using the rest parameter syntax. JavaScript function getSum(...numbers: number[]): number { return numbers.reduce((total, num) => total + num, 0); } const result = getSum(10, 20, 30, 40, 50); console.log(result); Output: 150Rest ArgumentsThese are arguments that we pass in while merging two data types (suppose concatenation of two arrays) using the same “…” (triple dots).These types of arguments are generally used for merging or concatenation or for any other operational purpose by itself.Syntaxlet generateGreeting = (greeting: string, ...names: string[]): string => { return greeting + " " + names.join(", ") + "!"; } Example: In this example, we will concatenate several strings which are passed inside the function as arguments. JavaScript let generateGreeting = (greeting: string, ...names: string[]): string => { return greeting + " " + names.join(", ") + "!"; } // Function call console.log(generateGreeting("GeeksforGeeks ", "is a computer science portal ")); Output: GeeksforGeeks is a computer science portal ! Reference: https://www.typescriptlang.org/docs/handbook/2/functions.html#rest-parameters-and-arguments Comment More infoAdvertise with us Next Article Explain about rest parameters and arguments in TypeScript 21mcsrltd Follow Improve Article Tags : TypeScript Geeks Premier League 2023 Similar Reads Explain about rest parameters and arguments in TypeScript In this article, we will try to understand all the basic facts or details which are associated with Rest Parameters and Arguments in TypeScript. Rest Parameters: Rest Parameter allows us to accept zero or more arguments of the specified type.A function (or a method) has only one rest parameter.This 3 min read 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 Arguments 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[]) 2 min read TypeScript Parameter Type Annotations TypeScript Parameter type annotations are used to specify the expected data types of function parameters. They provide a way to explicitly define the types of values that a function expects as arguments. Parameter type annotations are part of TypeScript's static typing system, and they help catch ty 2 min read TypeScript Generic Parameter Defaults TypeScript Generic Parameter Defaults allow you to specify default values for generic type parameters. This feature provides a fallback type when no explicit type argument is given, making generic types more flexible and easier to use, particularly when type inference is not straightforward.Syntaxfu 3 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 Like