【发布时间】:2016-07-30 17:29:06
【问题描述】:
我对您应该如何在 Typescript 中建模 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”。
那么我应该如何对此进行建模,在您在模块的命名空间中声明一个类之后,Typescript 似乎变得有点棘手,并且这些类型都不能存在于它们自身中?
a.b.c.d.e.f() 在.d.ts 文件中会是什么样子?
【问题讨论】:
标签: javascript typescript definition typescript-typings