In TypeScript inheritance works as it does in C# except that the keyword extends is used, and the base class is referred to as "super." This is shown in a demo.
- [Narrator] Inheritance, again, works much…as you're used to from C#,…however, instead of using a colon,…we use the keyword extends,…and we refer to the base class as super.…Note, that there is no use of the keyword virtual.…Methods are overridden in the derived class,…by giving them the same name as a method in the super class.…Overriding methods can call up into the super method.…Where things can get a bit confusing,…is in creating the constructor for the derived class,…as we'll see in this demo.…
Let's create a new file called Inheritance.ts.…The class that we want to derive from is Person,…so let's go back to classes2, take class Person2,…and copy that class.…That's going to be our base class.…We'll return to Inheritance.ts and drop that in,…and why not rename it just Person.…Now, it's going to complain because…it considers this all one project…and Person already exists, but that's no problem.…
The next class that we want to create is…the class that derives from Person,…so let's create a class Student,…and the way we say that it derives from Person…
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