【发布时间】:2017-01-08 17:25:17
【问题描述】:
如果我键入一个名为“foo”的模块,如下所示:
declare module "foo" {
interface App {
bar: boolean;
}
namespace foo {}
function foo(): App;
export = foo;
}
当导入另一个名为foo-plugin 的模块时,如何向App 接口添加新属性?
declare module "foo-plugin" {
interface App {
additional: string;
}
}
我尝试了https://www.typescriptlang.org/docs/handbook/declaration-files/templates/module-plugin-d-ts.html 中描述的模式,但它不起作用,它只能看到bar 属性。
如果我将 App 界面设为顶级,则合并声明,但无需导入 foo-plugin。
这就是 chai-as-promised 和 sinon-chai 发生的情况。此代码可以编译,但当然会引发异常,因为 eventually 未定义。它是某种 Typescript 限制并且必须被接受吗?
import { expect } from 'chai';
describe('Dummy', () => {
it('passes', () => {
expect('foo').to.eventually.equal(5);
});
});
谢谢..
【问题讨论】:
-
在你的扩展程序上使用相同的包名
declare module "foo" {
标签: typescript