1
我對你如何在Typescript中建模API有點困惑。在Typescript聲明文件中建模(long-ish)API
我想給hexo API,其中例如使用,看起來模型有點像這樣:
hexo.extend.tag.register(name, function(args, content){
// ...
}, options);
到目前爲止,我已經得到的東西,看起來像這樣:
//hexo.d.ts
declare module 'hexo' {
namespace extend {
export class tag {
public register: _register;
}
}
}
declare class _register {
name: string;
callback(args: any, content: any);
options: _options;
}
declare class _options {
ends: boolean;
}
然而,我得到的問題如下:
'typeof tag'類型中不存在屬性'register'。
所以,我應該怎麼建模,它好像打字稿變得有點棘手,你有一個模塊中聲明命名空間中的一類之後,並沒有這些類型的可以在自己的存在嗎?
a.b.c.d.e.f()
在.d.ts
文件中看起來像什麼?