TypeScript编译成AMD模块时如何继承已有的AND js class?

How to inherit from existing AMD js class in TypeScript compilng to AMD module?

我确实尝试了以下方法:

class Child {
    public func() {
       alert("hello");
    }
    constructor() {
        Parent.apply(this, arguments);
    }
}
Child["prototype"] = Object.create(Parent.prototype)
Child["prototype"].constructor = Child;

但是 Child class 的实例没有 func() 方法。

js如何继承class?

一般情况

只需使用 declare 即可声明现有的 class。

declare class Parent { // produces no JS code
    constructor(val);
}
class Child extends Parent {
    constructor(val) {
        super(val);
    }
}

外接模块(AMD)的情况

必须在定义文件中描述外部模块.d.ts

文件ContainerSurface.d.ts:

declare class ContainerSurface {
  constructor(options);
}
export = ContainerSurface;

使用方法:

import ContainerSurface = require('ContainerSurface');

class Child extends ContainerSurface {
  constructor(options) {
    super(options);
  }
}