[英]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.