O'Reilly logo

Learning Angular for .NET Developers by Rajesh Gunasundaram

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Inheritance in TypeScript

We just saw how to implement an inheritance in JavaScript using a prototype. Now, we will see how an inheritance can be implemented in TypeScript.

In TypeScript, similar to extending interfaces, we can also extend a class by inheriting another class, as illustrated:

class SimpleCalculator {     z: number;     constructor() { }     addition(x: number, y: number) {         z = x + y;     }     subtraction(x: number, y: number) {         z = x - y;     } }  class ComplexCalculator extends SimpleCalculator {     constructor() { super(); }     multiplication(x: number, y: number) {         z = x * y;     }     division(x: number, y: number) {         z = x / y;     } } var calculator = new ComplexCalculator(); calculator.addition(10, 20); calculator.Substraction(20, 10); calculator.multiplication(10, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required