-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Description
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:
-
The definition contains
declare module 'underscore.string'. The quoted name automatically makes it an external module. -
Had it been
declare module underscoreString, it would still have been an external module because of its use ofexport =. -
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) -
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. -
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.
-
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.
-
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