繁体   English   中英

Typescript:如何在构造函数上声明原型对象的类型

[英]Typescript : How do I declare type of prototype Object on constructor Function

我收到此编译错误:

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

在以下类上,如何从构造函数中获取打字稿以将原型对象识别为本地对象的一种类型?

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

declare var Base : IBase;

class Base implements IBase {

  constructor() {}

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

}

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);
  }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM