Is there a method in TypeScript to import
a module wrapped by webpack UMD (Universal Module Definition)? For instance:
npm install knockback
The file .js (
node_modules/knockback/knockback.js
) starts like this:
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory(require("knockout"), require("backbone"), ....
else if(typeof define === 'function' && define.amd)
define(["knockout", "backbone", "underscore"], function webpackLoadOptionalExternalModuleAmd( ....
});
else if(typeof exports === 'object')
exports["kb"] = factory(require("knockout"), require("backbone"), require("underscore"), (function ....
else
root["kb"] = factory(root["ko"], root["Backbone"], root["_"], root["jQuery"]);
When attempting to import this into a .ts file, tsc gives an error:
import * as k from 'knockback/knockback';
TS2307: Build: Cannot find module 'knockback/knockback'.
Are there any alternatives besides modifying the knockback.js file to make tsc recognize and import this .js? My Typescript version is 1.8.