我试图在Angular2应用程序中使用元素调整大小检测器库(https://github.com/wnr/element-resize-detector).
根据我有限的JS模块知识,该库似乎采用CommonJS格式.经过多次尝试,我创建了以下定义文件(*.d.ts):
declare module ResizeDetector {
function ResizeDetector(options: any): ResizeDetector.Erd;
interface Erd {
listenTo(element: any, resizeCallback: any): void;
uninstall(element: any): void;
}
}
export = ResizeDetector;
Run Code Online (Sandbox Code Playgroud)
然后我在我的TypeScript代码中使用以下import语句:
import * as ResizeDetector from 'element-resize-detector';
Run Code Online (Sandbox Code Playgroud)
运行我的应用程序并使用时console.log('ResizeDetector', ResizeDetector),将记录以下输出:
ResizeDetector function (options) {
options = options || {};
//idHandler is currently not an option to the listenTo function, so it should not be added to globalOptions.
var idHandler;
if (options.…
Run Code Online (Sandbox Code Playgroud)
这告诉我库已成功加载并且它按预期返回一个函数.
我的问题是我现在如何开始在TypeScript中使用库?当我尝试这样的事情:
private static resizeDetector = ResizeDetector({ strategy: 'scroll' }); …Run Code Online (Sandbox Code Playgroud)