This typescript:
export enum UID {
FACTORY,
ROBOT
}
compiles to this javascript:
(function (UID) {
UID._map = [];
UID._map[0] = "FACTORY";
UID.FACTORY = 0;
UID._map[1] = "ROBOT";
UID.ROBOT = 1;
})(exports.UID || (exports.UID = {}));
var UID = exports.UID;
I have to admit that the code seems rather obscure to me but I trusted the tsc compiler to know what it's doing. Unfortunately the javascript can't be executed. nodejs complains that:
(function (UID) {
^ TypeError: object is not a function
at ...
What have I done wrong ?
UPDATE: Matt B. has solved the problem. This is a known bug in the typescript compiler. tsc fails to insert semicolons after require statements, this can lead to strange errors. Manually adding the semicolons to my code solved the problem. Here's the link to the codeplex issue: http://typescript.codeplex.com/workitem/364
UPDATE 2: for those of you that experience the same error. You can insert the missing semicolons manually but that is not a very comfortable solution since you have to do this after every compilation. I noted that the problem only occurs with the enum. There are lots of other modules in the project and none of them have caused this error. Apparently a class definition is not "harmed" by the missing semicolons in front of it. Just move the definition of the enum behind one of your class definitions and the error should disappear. It's not sufficient to move the enum behind an interface since interfaces have no direct equivalent and are just deleted by the compiler
)
(in your error message) shouldn't be there:(function (UID)) {
. The code portion works fine: jsfiddle.net/antisanity/cRNeN – canon Mar 6 '13 at 16:59)
, not the sample posted. – Pointy Mar 6 '13 at 17:02exports
is already defined. – Matt Browne Mar 6 '13 at 17:29