Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upNamespace keyword #2159
Comments
danquirk
added
Suggestion
In Discussion
labels
Feb 27, 2015
This comment has been minimized.
This comment has been minimized.
nycdotnet
commented
Feb 27, 2015
|
Is this a keyword change only? For example, would clodules still be supported? (clamespaces?) |
This comment has been minimized.
This comment has been minimized.
|
It's an additional keyword that does the same thing. To the best of my understanding from current discussions, "clamespaces", "funspaces", and other exciting possibilities of names are just a nice bonus. |
This comment has been minimized.
This comment has been minimized.
NoelAbrahams
commented
Feb 27, 2015
|
I like this suggestion. We could make this change more potent by accompanying it with the math.ts namespace math {
export function add(x, y) { ... }
}foo.ts
This shouldn't be a breaking change because the error is only raised when the At the moment we are forced to keep our namespaces relatively flat in order to avoid problems with accessing deeply nested types: var foo = foo.bar.baz.bazooka.add(10,3); |
This comment has been minimized.
This comment has been minimized.
|
I strongly support this. The number of times I've had to explain is insane. Thanks! |
This comment has been minimized.
This comment has been minimized.
Steve-Fenton
commented
Feb 27, 2015
|
|
This comment has been minimized.
This comment has been minimized.
|
A crucial expectation for namespaces is to span multiple declarations.
Here both Red and Green are heavily implied to be in the same namespace, as opposed to the second one extending the first. Obviously, in JS/TS namespaces/internal modules actually create closures instead, see arguing about it on issue #447. This closure (and potentially an actual behaviour logic) doesn't quite fit with what 'namespace' implies. 'Module' is actually better.
However 'module' can become confusing after ES6 gains wider adoption. How about 'namespace module' instead?
That way it looks clearer to me. It still is havily hinting towards 'namespace modules' having behaviour, not just scope. But at the same time it's also clear those are some special modules, not your normal ES6 modules. |
This comment has been minimized.
This comment has been minimized.
|
@mihailik Not sure exactly what you mean. Multiple namespaces would let you span multiple declarations, just as internal modules do today. The codegen extends the existing module if it's there, rather than create a new closure each time. The linked issue seems to be more about the codegen being suboptimal in some cases. Unlike modules, which are based around a file and aren't extendable, namespaces (nee internal modules) are extendable. The only caveat is that closed-over non-exported symbols can't be seen across each namespace being merged, but I'd argue that's a good thing rather than a bad thing. |
This comment has been minimized.
This comment has been minimized.
Steve-Fenton
commented
Mar 3, 2015
|
@jbondc external modules are called "Modules" in ECMAScript 6, so it makes sense to stick with calling them "Modules" in TypeScript. |
This comment has been minimized.
This comment has been minimized.
|
@jonathandturner the question is not whether it's a good or bad thing -- the question is whether it's a naturally expected thing. I'd say that 'namespace' suggests it's a syntactic construct, whereas 'module' suggests lifetime and behaviour. |
This comment has been minimized.
This comment has been minimized.
NoelAbrahams
commented
Mar 4, 2015
|
The objections to using |
This comment has been minimized.
This comment has been minimized.
nycdotnet
commented
Mar 4, 2015
I support this simply because of the possibility of funspaces. |
This comment has been minimized.
This comment has been minimized.
|
Great summary, @jbondc ! To me keeping 'module', but adding a qualifier makes most sense: clearer English, and greater backward and forward compatibility. Few more: scope module Colors {
export var Red = 'red8';
}
closure module Colors {
export var Red = 'red9';
}
extend module Colors {
export var Red = 'red10';
}Beware the familiarity of 'namespace' appealing to C#-aware folks! That's not a wise move to gain a wider foothold in JS universe. |
This comment has been minimized.
This comment has been minimized.
NoelAbrahams
commented
Mar 4, 2015
|
I'm not quite following the arguments. So we don't want to introduce a new keyword, and we don't want to do C#-aware stuff, but nobody complained about |
This comment has been minimized.
This comment has been minimized.
|
It's a fine line with C# and marketing. There's only so much of C# a layman JS developer is ready to take. Say, German cars are fantastic. But if they come with German shops, German pedestrians and German road signs -- I'd have hard time adapting. Not ready to learn another language, me. A bit of C# feels great. But sticking it everywhere, shoving it on the first line of every file -- that could feel just too foreign to a JS person. |
This comment has been minimized.
This comment has been minimized.
NoelAbrahams
commented
Mar 5, 2015
|
Makes perfect sense when the argument is couched in terms of Germans! I don't think it's absolutely correct to argue that since modules are emitted as JavaScript closures that one should call them that, because a closure is very much a JavaScript construct (read small code-base), and the code we write is more about managing related components spanning tens of thousands of LOC (for which JavaScript was not originally designed). I would like to see I don't really care much about what the keyword is called (so long as it keeps the Germans happy!) |
This comment has been minimized.
This comment has been minimized.
fletchsod-developer
commented
Mar 5, 2015
|
"namespace" is the right way to go. It's not just about C#, but JAVA and other languages too using that concept. Javascript is the only thing, I know of, that use module. I noticed people everywhere are moving toward higher level language that write Javascript for us so we don't have to know of more dirty, more lengthy & more complicated scripts. C# use "using", JAVA use "import", other language use "??" etc. that we don't have to write declaration stuff. |
DanielRosenwasser
referenced this issue
Mar 8, 2015
Closed
Opt-In Language Features to prevent Embrace and Extend -- Compiler options on tsc.js #2261
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
|
OK, but Java does not have a namespace keyword in the first place. The crucial problem with using 'namespace' is that it already HAS a very specific meaning in languages like C# and C++. It specifically is a name space, a space for names. It's a naming/addressing thing -- not a behaviour thing. Internal modules in TypeScript are emphatically not merely a naming tweak. Fundamentally those modules have lifetime and behaviour. Those are not just bolted-on aspects, the lifetime and behaviour of modules need to be actively managed. They cause their share of bugs, sometimes require careful re-ordering or renaming to ensure initialisers are executed correctly. The difference between TS 'internal module' and C# 'namespace' is like a difference between Class and Record in Turbo Pascal, if you know what I mean ;-) It does make sense to have a separate word for 'internal modules', but not necessarily a first borrowed idea from C# is the right one. |
This comment has been minimized.
This comment has been minimized.
fletchsod-developer
commented
Mar 9, 2015
|
I dont see in my comment that I say JAVA do have "namespace" keyword. Just saying it in layman term for programmers that understand the concept of it. |
This comment has been minimized.
This comment has been minimized.
NoelAbrahams
commented
Mar 9, 2015
|
If you would like the emit for namespaces to be different then that's just another suggestion. It doesn't really say anything about the need for wanting to have namespaces in TypeScript. |
This comment has been minimized.
This comment has been minimized.
|
As long as the project overlords at Microsoft are content with the existing TS adoption, reusing the C# 'namespace' keyword is the reasonable way to go. Conquering the minds of the JS folk is not necessarily the goal, right? ;-) |
mhegazy
referenced this issue
Mar 14, 2015
Closed
Greatly improve code sharing and reuse options #2327
NoelAbrahams
referenced this issue
Apr 7, 2015
Closed
Syntax : internal modules and ES6 modules #2649
This comment has been minimized.
This comment has been minimized.
yahiko00
commented
Apr 7, 2015
|
I've read this interesting discussion. Both clever arguments on both side. |
This comment has been minimized.
This comment has been minimized.
robertpenner
commented
Apr 19, 2015
|
It seems many agree that "external/internal modules" is now sub-optimal language and often confusing to explain. I would add that it's also confusing while coding, because the words While I was learning TypeScript modules, I was initially under the impression that I could write an internal module, then simply add a compiler flag to magically produce an external module. It took time to realize things like:
Overall, TypeScript's module terminology meant that, once I was comfortable with internal modules and started to create external modules, I had to "unlearn" assumptions I had made. |
This comment has been minimized.
This comment has been minimized.
robertpenner
commented
Apr 19, 2015
|
Re: the "namespace and C#" concern, I say this with love: the world does not revolve around C#. |
This comment has been minimized.
This comment has been minimized.
robertpenner
commented
Apr 19, 2015
|
In ES4, http://www.ecma-international.org/activities/Languages/Language%20overview.pdf
ES4 namespaces always seemed a bit esoteric. I'd say few AS3/Tamarin developers ever made their own namespaces, whereas everyone created packages. Explanations of ES4 namespaces: That being said, ES4's definitions of |
ahejlsberg
self-assigned this
Apr 27, 2015
This comment has been minimized.
This comment has been minimized.
|
Closed in #2923. |

Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.

jonathandturner commentedFeb 26, 2015
Now that we have ES6 modules in TypeScript, we should probably move towards a cleaner separation in the module types.
In truth, "internal modules" have been a bit of confusion for developers new to TypeScript. They're much closer to what most people would call a namespace.
Likewise, "external modules" in JS speak really just are modules now.
Let's move to a simpler explanation and have namespaces and modules be more separate. We'd still support the previous syntax, but this would mean introducing a new keyword called 'namespace' that was a bit easier to read and doesn't conflict with ES6 terminology.
Before:
After: