JCM*_*JCM 2 javascript types typescript
该hubot类型定义有以下类:
declare namespace Hubot {
// ...
class Message {
user: User;
text: string;
id: string;
}
// ...
}
// Compatibility with CommonJS syntax exported by Hubot's CoffeeScript.
// tslint:disable-next-line export-just-namespace
export = Hubot;
export as namespace Hubot;
Run Code Online (Sandbox Code Playgroud)
我想Message从我的代码中增加这个类,在hubot.d.ts我编写的文件中:
import * as hubot from 'hubot';
declare namespace Hubot {
export class Message {
mentions: string[]
}
}
Run Code Online (Sandbox Code Playgroud)
该hubot.d.ts文件包含在代码中
"files": ["types/custom/hubot.d.ts"]
Run Code Online (Sandbox Code Playgroud)
在tsconfig.json文件中。
我缺少什么?有没有办法做到这一点?
hubot.d.ts 应包含:
// This import serves no purpose except to make the file a module
// (so that the following statement is a module augmentation rather
// than a module declaration) and could be replaced with `export {}`.
import * as hubot from 'hubot';
declare module "hubot" {
interface Message {
mentions: string[]
}
}
Run Code Online (Sandbox Code Playgroud)
需要一个模块扩充来向hubot模块添加声明。由于Hubot命名空间被分配为模块的导出,因此对模块所做的任何扩充都将直接针对该命名空间;namespace Hubot { ... }在扩充中编写另一个会创建一个嵌套的名称空间,这不是您想要的。最后,声明一个类会产生“重复标识符”错误,而声明一个接口就足以添加属性。
| 归档时间: |
|
| 查看次数: |
656 次 |
| 最近记录: |