How do I import an AMD module that's only resolvable at runtime? (using RequireJS.config with path+shim)

Topics: General
Apr 22, 2013 at 4:14 PM
Edited Apr 22, 2013 at 4:30 PM
I have a project using RequireJS and AMD modules. Now I want to import some old-skool javascript modules. Since I use RequireJS I followed this guide to setup require.config with paths and shims:

But this guide only has the modules accessible in the main file using a require(), while I want to import() these modules in a TypeScript submodule (one that also has some other import/export statements).
import myShimmed = module('myShimName');
import myRegular = module('myRegularModule');

export class MyClass {
The compiler won't do this because it cannot find the 'myShimName' module I've setup in the RequireJS config. The only way I can make it load the dependency runtime without compiler error is to use an AMD define(), but then I cannot define classes and modules.

So how do I let TypeScript generate the proper require statements without complaining about missing files?

edit: I know I could load the shimmed modules in the regular require in the main file and use some globals but that defeats the whole purpose of dependency resolution.
Apr 23, 2013 at 12:59 AM
If I understand correctly, you can use declare modules to help fill out the information of what is being imported for the TypeScript compiler. Something like:
declare module "myModule" {
    export function moduleFunction(): string;

import baz = module("myModule");