Frage

Apparently, you can say 'export import xx = module("xx")' in TypeScript.

But what does that mean? I didn't see that in the spec.

War es hilfreich?

Lösung

Good observation.

This is a composition technique that makes the entire imported module act like an external module created within the enclosing module. Here is a shortened example:

module MyModule {
    export class MyClass {
        doSomething() {

        }
    }
}

declare module EnclosingModule {
    export import x = module(MyModule);
}

var y = new EnclosingModule.x.MyClass();

The export keyword on its own makes a module an external module. In this case, it is making MyModule an external module of the enclosing module even though it isn't originally defined inside of the enclosing module.

Why?

I guess this is a handy way of re-using modules rather than repeating them in different contexts - making them accessible in more than one place where it seems logical to do so.

Andere Tipps

As of 0.8.1.1, you apparently need to use this syntax when you're exporting classes that extend classes declared in other modules.

For instance, in 0.8.1, you could say this:

import mUiBase = module("../UiBase");

export class BaseViewModel extends mUiBase.UiBase {
}

But in 0.8.1.1, that gives you an error "Exported class extends class from private module", so you need to do this instead:

export import mUiBase = module("../UiBase");

export class BaseViewModel extends mUiBase.UiBase {
}

Presumably that's intended, and not just a bug.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top