Skip to content

Use external module in internal modules #557

@antoinebj

Description

@antoinebj

Hi,

I don't have a strong background in JavaScript, I have mainly been coding in C#.
I'm starting a client-side application using TypeScript and Angular.js and wish to use the underscore.string library, with its TS definition available on NuGet.

Here is an excerpt of that definition:

declare module 'underscore.string' {
    var underscoreString: UnderscoreStringStatic;
    export = underscoreString;
}

Here are my observations and assumptions:

  1. The definition contains declare module 'underscore.string'. The quoted name automatically makes it an external module.

  2. Had it been declare module underscoreString, it would still have been an external module because of its use of export =.

  3. If I write import _ = require('underscore.string') in the same file as an internal module (but not within the module), that internal module has to become external. Besides an error appears: Cannot compile external modules unless the '--module' flag is provided. (Which, in a VS project, means having to check either AMD or CommonJS in the project properties)

  4. If I try import _ = require('underscore.string') within an internal module, that internal module also has to become external, otherwise the following error appears: Import declarations in an internal module cannot reference an external module.

  5. The language specification for v1.0 mentions an ImportDeclaration in section 10.3:

import Identifier = EntityName;

However this only applies to internal modules, which 'underscore.string' is not if my first assumptions are correct.

  1. If I change my internal modules to be external, they won't be open-ended anymore and I will need to name a different module for each of my files.

  2. I do not have difficulty using Angular.js because it was declared as an internal module.

Now, my main question is:
How can I use what appears to be an external module ('underscore.string') in my open-ended internal modules?

If I can't, then my corollary question is:
What is the most convenient way to structure the application without having to declare a new external module for each file? Especially since I would only name those modules after the sole class they contain (I follow C# convention of 1 class = 1 file).

Ideally I would deal with modules as I deal with .NET namespaces, but the way it looks now, I would have to deal with them as if every file were a .NET assembly.

Thanks in advance for any clarification

Metadata

Metadata

Assignees

No one assigned

    Labels

    QuestionAn issue which isn't directly actionable in code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions