Search
 
SCRIPT & CODE EXAMPLE
 

TYPESCRIPT

rest parameters in typescript

A rest parameter allows you a function to accept zero or more arguments
of the specified type. In TypeScript, rest parameters follow these rules:

1. A function has only one rest parameter.
2. The rest parameter appears last in the parameter list.
3. The type of the rest parameter is an array type.

// Example: 
function getTotal(...numbers: number[]): number {
    let total = 0;
    numbers.forEach((num) => total += num);
    return total;
}

console.log(getTotal()); // 0
console.log(getTotal(10, 20)); // 30
console.log(getTotal(10, 20, 30)); // 60
Comment

PREVIOUS NEXT
Code Example
Typescript :: rewrite requests htaccess 
Typescript :: literal types typescript 
Typescript :: how to add custom snippets in emmet in visual studio code 
Typescript :: what is data type in data structure 
Typescript :: typescript pick 
Typescript :: why important testng xml file 
Typescript :: typescript number to hex string 
Typescript :: use pipe in ts file angulr 
Typescript :: styled components type argument generic 
Typescript :: google sheets query multiple or 
Typescript :: validate int have 3 digits c# 
Typescript :: botocore.exceptions.ClientError: An error occurred (AccessDenied) when calling the ListObjects operation: Access Denied 
Typescript :: How to use the Generic Type Format for Arrays in Typescript 
Typescript :: world-times-newspaper-magazine-style-ghost-blog-theme 
Typescript :: typescript react switch case component 
Typescript :: 8.1.3. Varying Data Types¶ Arrays 
Typescript :: Please fill in the missing parts of the code to print "I love C++" on the screen. 
Typescript :: undetermined number of arguments in function r 
Typescript :: how to run springboots processbuilder 
Typescript :: ngx-numeral 
Typescript :: listen to hub events asw analytics 
Typescript :: .env.local is not working inside useEffect 
Typescript :: fputs c++ 
Typescript :: Algebra is simply overlaying sets of equations onto the world around us. 
Typescript :: ts Command pattern 
Typescript :: ?In static pages, the contents are fluid and changeable (e.g., rotating banners). 
Typescript :: how to get ppt screen shots from a video using python :: keyframes 
Typescript :: subscripts list c# 
Typescript :: Error detected in pubspec.yaml: No file or variants found for asset: assets/imgs. 
Typescript :: Define a function sum_two_gr with three arguments returning the sum of the greatest two python 
ADD CONTENT
Topic
Content
Source link
Name
4+1 =