Function overloading serves the same purpose in TypeScript as it does in C# but the syntax is radically different, and their use is more constrained.
- [Narrator] Just as in C Sharp,…you can overload a function by changing its signature.…However, the way you do this in TypeScript…is quite different.…First, you declare the various overloaded functions,…and then you must define an implementation signature,…as shown in the next demo.…Let's create a new file,…and we're going to call that overloading.ts.…And here, we're going to create an overloaded function.…We'll call that function person.…So, the first overload is going to be called person,…and that's going to take a parameter name,…which is of type string.…
And the function itself will return string.…Now, notice there'll be no body for this function…at the moment.…We're then going to overload person…to take an age, which will be of type number,…as you would expect.…And that, too, will be a function of type string.…Let's do one more overload of person,…which will take a boolean isMarried.…And as you might expect by now,…that, too, will be of type string.…
That is, the function itself is of type string.…Now we come to the interesting part,…
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