Description
Use case: express.d.ts
on DefinitelyTyped:
https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/express/express.d.ts
Here, express exposes a namespace Express
to let us extend Request
via declaration merging.
Unfortunately those extensions cannot contain types imported from ambient external "modules"
, which means they're of limited use. You can't import {RedisClient} from 'redis'
and define that such a client is attached to a Request
(you're not allowed to import ambient external modules into a namespace declaration)
However, since express-the-module is also a function, the only way to declare the module is to use declaration merging then write export = mergeCombination
at the end. This means that we can't use ambient external module merging either
Since lots of node modules love this "module is function and also namespace" approach, this isn't an isolated case.
I really think we need syntax that allows us to export functions and class constructors from module declarations together with everything else. Declaration merging with export = x
syntax is cool, but it really is a hack when its used because of the lack of this feature.
Syntax (just to get started, I'm sure someone will have better ideas)
export new(x:string):MyType;
export (x:string):string;
// Generics
export new<T>(x:T):MyType<T>;
export <T>(x:T):T;