我正在尝试为存在的hapi定义添加新类型... 我想添加seneca类型......这是示例
interface SenecaMethods {
act: any;
add: any;
}
interface HapiServer extends Hapi.Server {
info: any;
seneca: SenecaMethods;
}
const server: HapiServer = new Hapi.Server();
返回错误服务器无法分配给HapiServer,属性 类型服务器中缺少'seneca'。
如何将seneca方法添加到Hapi.Server?我可以将seneca作为可选项,但我不希望它是可选的....
答案 0 :(得分:3)
您有几个选择:
演员:
const server: HapiServer = new Hapi.Server() as HapiServer;
//server.seneca === undefined
<强>联合强>
const server: HapiServer = Object.assign(new Hapi.Server(),
{ seneca: { act: "foo", add: "bar" } }
)
<强>延伸强>
class MyHapiServer extends Hapi.Server {
info: any;
seneca: SenecaMethods;
constructor(){
super();
this.seneca = {
act:"foo",
add:"bar",
}
}
}
const server: MyHapiServer = new MyHapiServer();