Reputation: 9113
Lots of type definition files make use of the export =
directive, such as:
declare module "i40" {
interface RouterStatic {
() : Router;
}
interface RouteInfo {
params : {
[key : string] : any;
};
splats : string[];
route : string;
fn : Function;
next : any;
}
interface Router {
addRoute(routeString : string, action ?: Function);
match(test : string) :RouteInfo;
}
export = null as RouterStatic;
}
Alternatively, someone might've written code like:
export interface Blah {}
const x = {hi : 5};
export = x;
EDIT: This code used to work once, but as of the current version (2.6), it won't compile. The compiler says that I can't use export =
if I export other stuff from the module. Which makes sense.
How do I import one of the interfaces in the module? None of the following works.
import Router = require('i40');
let x : Router.RouteInfo; //RouteInfo not found
import {RouteInfo} from 'i40'; //RouteInfo not found
import * as Router2 from 'i40'; //Error, i40 is not a module
Upvotes: 2
Views: 475
Reputation: 23483
I'd say (Ref modules under Ambient Modules
)
declare module "i40" {
interface RouterStatic {
...
}
interface RouteInfo {
...
}
interface Router {
...
}
export { RouterStatic, RouteInfo, Router } as RouterStatic;
}
import * as Router2 from 'i40';
// use as Router2.RouterStatic, etc
// or
import { RouterStatic, RouteInfo, Router } from 'i40';
// use as RouterStatic, etc
Upvotes: 2