Angular — Typescript Abstract Classes

DevJo
3 min readOct 3, 2021

So you use Typescript classes for coding Angular / React projects, but do you know what are abstract classes in typescript?

Abstract classes are mainly for inheritance where other classes may derive from them. We cannot create an instance of an abstract class.

Abstract class cannot be instantiated

Typescript abstract classes are similar to a lot of other languages, such as Java, C++, Python and many more. It is not uncommon that people use abstract classes in their code, so that common methods or functionalities can be inherited/derived from the abstract(base) class.

Derive class extends Abstract class

In abstract classes, you can easily inject dependencies into it and the derived classes are able to access the methods that fetch the data from your backend once and shared it across all the derived classes.

Abstract class with MatSnackBar dependency to show toast

--

--