TypeScript Rest Parameters and Arguments Last Updated : 28 Apr, 2025 Comments Improve Suggest changes 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 TypeScript Rest Parameters and Arguments 21mcsrltd Follow Improve Article Tags : JavaScript Web Technologies Geeks Premier League TypeScript Geeks Premier League 2023 +1 More 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 TypeScript Optional Parameters in Callbacks In TypeScript, optional parameters in callbacks are parameters that may or may not be provided when the callback function is invoked. They are denoted by a ? after the parameter name, allowing for more flexible function calls without requiring all arguments.Syntaxtype MyCallback = (param1: string, p 2 min read Rest Parameters in LISP LISP Function's parameters list has a basic aim of declaring the variables which will receive the arguments that are passed in the function. Normally parameter list contains a basic list of variable names, those parameters are called "required parameters". If a function is called, for every required 3 min read Explain the Rest parameter in ES6 In this article, we will try to understand the details associated with the rest parameter in ES6 which includes the syntax of rest parameters, and how to use this with the help of certain examples. The rest parameter is an improved way to handle function parameters, allowing us to handle various inp 3 min read How Are Parameters Sent In An HTTP POST Request? HTTP POST requests are widely used in web development to send data from a client to a server. Whether you're submitting a form, uploading a file, or sending JSON data via an API, understanding how parameters are sent in an HTTP POST request is important. In this article, weâll explore how are parame 4 min read Like