I\'m trying to implement a method in a super class that should be available for use, but not changeable, in sub classes. Consider this:
export abstract clas
Example of implementation hack of 'sealed method' as readonly property of type function which throws compiler error when attempting to override in extended class:
abstract class BaseClass {
protected element: JQuery;
constructor(element: JQuery) {
this.element = element;
}
readonly public dispose = (): void => {
this.element.remove();
}
}
class MyClass extends BaseClass {
constructor(element: JQuery) {
super(element);
}
public dispose(): void { } // Compiler error: "Property 'dispose' in type 'MyClass' is not assignable to the same property in base type 'BaseClass'"
}
TypeScript 2.0 supports "final" classes through using of private constructor:
class A {
private constructor(){}
}
class B extends A{} //Cannot extend a class 'A'. Class constructor is marked as private.ts(2675)