I am trying to use the element-resize-detector library (https://github.com/wnr/element-resize-detector) in an Angular2 application.
From my limited JS module knowledge, the library appears to be in CommonJS format. After several attempts, I have created the following definition file (*.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;
I then use the following import statement in my TypeScript code:
import * as ResizeDetector from 'element-resize-detector';
When running my app and using console.log('ResizeDetector', ResizeDetector), the following output is logged:
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.…
This shows me that the library is successfully loaded and that it returns a function as expected.
My question is how can I now start using the library in TypeScript? When I attempt something like:
private static resizeDetector = ResizeDetector({ strategy: 'scroll' });
I get the following transpile error:
error TS2349: Cannot invoke an expression whose type lacks a call signature.