Reputation: 32926
It looks like I have to do full naming when accessing a TypeScript module in javascript. Is this correct?
My TypeScript is:
export module App.editor.menu {
export class File {
static isOpenEnabled() {
return false;
}
static openClicked() {
debugger;
}
}
}
And my javascript is:
Ext.onReady(function () {
define(["../../scripts/ribbon", "./menu-handler"], function (ribbon, handler) {
And I have to call "handler.App.editor.menu.File.isOpenEnabled()" instead of "handler.isOpenEnabled()"
All the examples I've seen don't require the namespace be included. But I haven't seen any examples that are half TypeScript, half javascript so I figure this might be different.
Is the full namespace required in this case?
Upvotes: 0
Views: 930
Reputation: 220964
The idea with namespaces is that you want to avoid name conflicts and clearly specify the domain of a particular type or variable. This is important in things like .NET where the transitive closure of all required types are getting loaded into one domain and a name collision would be highly problematic.
In an external module, this is wholly unnecessary because the code that loads you gets to define exactly what identifier you are bound to, and callers will only be "seeing" the code that they explicitly import.
In general, you should not have a TypeScript file whose only top-level element is export module
. Move everything outside and put export
on it so your callers can find it more easily. In your specific example, your file should just say:
export class File { ... }
without being in a module (unless you have a bunch of other subdivisions you really want to expose through one external module, which is unlikely).
Upvotes: 1