Consider the following TypeScript code:
import P = module("Person");
export module Database {
export class DB {
public findPerson(id: number): P.Models.Person {
return new P.Models.Person("Rock", "Strongo");
}
}
}
This compiles into the following Javascript:
var P = require("./Person")
(function (Database) {
var DB = (function () {
function DB() { }
DB.prototype.findPerson = function (id) {
return new P.Models.Person("Rock", "Strongo");
};
return DB;
})();
Database.DB = DB;
})(exports.Database || (exports.Database = {}));
Notice the lack of a semi-colon on the require statement. This is causing problems with execution of the javascript code in node.js.
$ node Test.js
DB.js:2
(function (Database) {
^
TypeError: object is not a function
at Object.<anonymous> (DB.js:2:1)
at Module._compile (module.js:449:26)
at Object.Module._extensions..js (module.js:467:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:362:17)
at require (module.js:378:17)
at Object.<anonymous> (Test.js:1:71)
at Module._compile (module.js:449:26)
at Object.Module._extensions..js (module.js:467:10)
If you put the semi-colon on the require statement in the .js file, it works fine.
For a full example, see the attached files. Do
tsc Test.ts
node Test.js