0

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?

2
  • Where do these modules exist? Are they under window? Commented Oct 25, 2016 at 8:51
  • I am working with NativeScript which has a "pattern" of declaring type definition files for the native Android/iOS libraries in a separate .d.ts file in order to remove those warnings during development, they are correctly resolved by the {N} runtimes afterwards. The code snippet above is a simplified version of such files but basically it is as you see it in a single file. The same in an .ts file is also throwing this error. Commented Oct 25, 2016 at 10:12

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for the response, I am well aware I can use different names as stated in my questions text but wanted to see if I am not missing something. Thanks.
Then you need to add a common parent module
0

You can use the type keyword to declare an alias for final.Test before declaring module.root like this:

declare module final {
    export class Test {
    }
}

// define 'finalTest' as an alias
type finalTest = final.test;

declare module root {
    module final {
        export class MainClass extends finalTest {
        }
    }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.