abstract classes and methods

TypeScript 1.6 adds support for abstract keyword for classes and their methods. An abstract class is allowed to have methods with no implementation, and cannot be constructed.

Examples
  1. abstract class Base {
  2. abstract getThing(): string;
  3. getOtherThing() { return 'hello'; }
  4. }
  5. let x = new Base(); // Error, 'Base' is abstract
  6. // Error, must either be 'abstract' or implement concrete 'getThing'
  7. class Derived1 extends Base { }
  8. class Derived2 extends Base {
  9. getThing() { return 'hello'; }
  10. foo() {
  11. super.getThing(); // Error: cannot invoke abstract members through 'super'
  12. }
  13. }
  14. var x = new Derived2(); // OK
  15. var y: Base = new Derived2(); // Also OK
  16. y.getThing(); // OK
  17. y.getOtherThing(); // OK