Maximus Maximus - 1 year ago 80
TypeScript Question

Why use abstract class instead of interface if no methods are implemented

Angular2 in its file

declares class as abstract

export abstract class OnInit { abstract ngOnInit(): void; }

why not declare it as interface since it doesn't have implementation?

Answer Source

Interfaces don't exist in java-script; So, presumably, using abstract classes (that don't have any member implementations) is a useful way to have that "contract" have a real type at run time. One possible use would be for dependency injection.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download