0

我得到这个编译错误:

“基础”类型的值上不存在属性“原型”

在下面的类中,我怎样才能让 typescript 将原型对象识别为构造函数函数中的原生对象类型?

interface IBase {
  extend: any;
  prototype : any;
}

declare var Base : IBase;

class Base implements IBase {

  constructor() {}

  public extend( mixins : any ) : void {
    _.extend( this.prototype, mixins );
  }

}
4

1 回答 1

3

this.prototype可能不是您的意思,因为实例Base没有prototype属性(在运行时查看自己)。Base,但是,确实:

interface IBase {
  extend: any;
}

class Base implements IBase {
  constructor() {}

  public extend( mixins : any ) : void {
    _.extend(Base.prototype, mixins );
  }
}

当然,此时extend也可能是静态的,因为它适用于所有Base实例。你的意思是这个吗?

  public extend( mixins : any ) : void {
    _.extend(this, mixins);
  }
于 2013-04-13T15:58:36.493 回答