[英]Typescript : How do I declare type of prototype Object on constructor Function
I get this compile error: 我收到此编译错误:
property 'prototype' does not exist on value of type 'Base' 属性“原型”在类型“基础”的值上不存在
on the following class, how can I get typescript to recognise the prototype object as a type of native Object from a 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
is probably not what you mean, since instances of Base
don't have a prototype
property (see yourself at runtime). this.prototype
可能不是您的意思,因为Base
实例没有prototype
属性(请在运行时查看)。 Base
, however, does: 但是, Base
可以:
interface IBase {
extend: any;
}
class Base implements IBase {
constructor() {}
public extend( mixins : any ) : void {
_.extend(Base.prototype, mixins );
}
}
Of course, at this point, extend
might as well be static, since it applies to all Base
instances. 当然,在这一点上, extend
可能也是静态的,因为它适用于所有Base
实例。 Did you mean this instead? 你是说这个吗?
public extend( mixins : any ) : void {
_.extend(this, mixins);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.