7

Closed

Typescript fails to generate semi-colons for require statements

description

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

file attachments

Closed Jun 25, 2013 at 12:19 AM by danquirk
This has been fixed in the latest bits in the develop branch.

comments

dland wrote Nov 2, 2012 at 11:17 PM

How do you attach multiple files with this thing without zipping them up?

nabog wrote Nov 4, 2012 at 8:43 AM

RyanCavanaugh wrote Nov 5, 2012 at 11:57 PM

Thanks for reporting this issue! Marking it as 'Active' (to be fixed).