I have several jQuery plugins that I would like to load using the AMD template in TypeScript. For example, I might have this structure:
/lib/jquery.myplugin.js /app.ts
The plugin simply extends jQuery. It does not provide any new functions or top-level variables. An example would be:
The corresponding jquery.myplugin.d.ts file looks like this:
interface JQuery { myExample(); }
So now in app.ts I can name something like $('#my-element').myExample() . Note that this assumes that I already have jquery.d.ts ads from a downloaded by Microsoft.
My question is how to load this library asynchronously and use TypeScripts static typing? I could use it like this:
but this requires me to add the <script> to my HTML, and the library does not load asynchronously. I want TypeScript to generate this code:
define(["require", "exports", "lib/jquery.myplugin"], function (require, exports, __jquery.myplugin__) { ...
However, since there is no export in the .d.ts file, I cannot write import myplugin = module('lib/jquery.myplugin') .
The closest I got is to make jquery.myplugin.d.ts , which links to another ts file with an interface declaration and includes at least one export. However, there is nothing to export in this library, and to get the desired result, I need to not only add the export, but also call it.
Update . I opened a work item for this on typescript.codeplex.com
javascript typescript js-amd
dcstraw
source share