![](/img/trans.png)
[英]How to declare TypeScript type of function that returns own prototype?
[英]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.