Reputation: 3857
I did try the following:
class Child {
public func() {
alert("hello");
}
constructor() {
Parent.apply(this, arguments);
}
}
Child["prototype"] = Object.create(Parent.prototype)
Child["prototype"].constructor = Child;
but the instance of the Child class doesn't have func() method.
How to do inheritance from js class?
Upvotes: 1
Views: 304
Reputation: 23702
Just use declare
in order to declare an existing class.
declare class Parent { // produces no JS code
constructor(val);
}
class Child extends Parent {
constructor(val) {
super(val);
}
}
The external module has to be described in a definition file .d.ts
.
File ContainerSurface.d.ts
:
declare class ContainerSurface {
constructor(options);
}
export = ContainerSurface;
How to use it:
import ContainerSurface = require('ContainerSurface');
class Child extends ContainerSurface {
constructor(options) {
super(options);
}
}
Upvotes: 4