我使用这样的记录方法安装了knockout
定义。
npm install @types/knockout
它工作得很好,我可以像这样在任何地方导入它。
import * as ko from "knockout";
但是,我坚持KnockoutStatic
使用一些自定义的东西来扩展接口。我正在尝试迁移一个<reference ... />
基于namespace
大型 TS 应用程序以使用模块。以前,我很容易在任何地方声明扩展接口,并且声明被合并了。假设我的扩展看起来像这样。
interface KnockoutStatic {
doSomething(): void;
}
我试图创建一个KnockoutExtensions.d.ts
我这样声明的文件。
import "knockout";
declare module "knockout" {
export interface KnockoutStatic {
doSomething(): void;
}
}
但是当我在某处同时导入knockout
我的扩展程序时,TS 仍然无法解析doSomething
呼叫。
import * as ko from "knockout";
import "./KnockoutExtensions";
ko.doSomething(); // error
d.ts
使用 TypeScript 2.0 和新子系统扩展库接口的正确方法是什么?
我正在使用安装了 TypeScript 2.0 的 Visual Studio 2015 Update 3。