TypeScript interfaces in Angular

After reading Angular Fundamentals I got to know that you cannot use Typescript interfaces as a dependency injection token. This is because interfaces has no representation in runtime i.e. Javascript therefore Angular has no means to determine the type of dependency. However I found a quick workaround that worked for me like a charm most of the time. Simply convert interface to an abstract class! It's as simple as renaming interface to abstract class. The only downside is that abstract classes don't support multiple inheritance but in many cases it's not needed.

Comments

Popular posts from this blog

Demystifying fast up-to-date check in Visual Studio C# projects

TFS Proxy not working: The source control proxy is not responding

Bitcoin, Docker, Microservices, etc.