Vladimir Amiorkov Vladimir Amiorkov - 1 month ago 5
TypeScript Question

Module name overlapping issue in TypeScript

I am not sure if this is supported or not but I have a scenario where in my d.ts file I want to have the following declarations:

declare module final {
export class Test {

}
}

declare module root {
module final {
export class MainClass extends final.Test {

}
}
}


And the issue I having is that TypeScript "Property 'Test' does not exist on type 'typeof final'" for the
extends final.Test
part.

So we are having a module name overlapping issue, is that resolvable without the need to make the names unique?

Answer

There's no way to specify that you mean the other final module.
What you can do is to name your modules with different names:

declare module final1 {
    export class Test {}
}

declare module root {
    module final2 {
        export class MainClass extends final1.Test {}
    }
}

Or you can place then under a shared parent:

declare module myModule {
    export module final {
        export class Test {}
    }
}

declare module myModule {
    declare module root {
        module final {
            export class MainClass extends myModule.final.Test {}
        }
    }
}

In the browser there's already a shared parent which is the window so you can just do:

export class MainClass extends window.final.Test {}

But I'm unsure how that's done in NativeScript.