Rest parameters serve the same function as the keyword "params" in C#, though their syntax is considerably different. The use of rest parameters is illustrated in this demo.
- [Instructor] There are many time you don't know…how many parameters you'll want to pass…into a function at one time.…In C#, we solved this with the params keyword,…In TypeScript, this is solved with rest parameters.…They are preceded by three dots,…and followed by square brackets.…This is easier to understand when seen,…so let's take a look at this demo.…We're going to create a new file.…Let's call it restParams, and don't forget…that .ts at the end to signal, once again,…to VS code that we are in a TypeScript file.…
We're going to create a function called addWithRest,…and that function is going to be familiar to you…because the first two parameters will be num1 and num2s.…So we'll say num1 is a number,…and we'll say num2 is a number.…Now we want to be able to add as many other parameters…as we like, much as we do with params in C#.…The way we do that is we begin with an ellipsis,…that is three dots, then the name of the variable,…in this case we'll call it numbers,…and notice that it's plural because it really is an array,…
In this course, Jesse Liberty reviews the fundamentals of TypeScript for the C# developer, including the built-in types, flow controls, and functions. He covers default, optional, and rest parameters; lambda functions; object literals; and the creation and use of custom classes. Plus, learn about other object-oriented features such as inheritance and interfaces. By the end of the course, C# developers should be well on their way to incorporating this flexible and powerful web programming language into their app development workflow.
- Setting up a TypeScript development environment
- Working with types and variables
- Using operators to control flow
- Working with parameters and functions
- Creating classes and objects
- Exploring TypeScript inheritance
- Working with interfaces