Just starting out with typescript. Here's the code I've been experimenting with:
module app.controllers {
export class FooController {
}
}
module app.controllers {
export class BarController {
}
}
After running tsc
with options --module amd
and outFile app.js
, this is the generated result:
var app;
(function (app) {
var controllers;
(function (controllers) {
var FooController = (function () {
function FooController() {
}
return FooController;
}());
controllers.FooController = FooController;
})(controllers = app.controllers || (app.controllers = {}));
})(app || (app = {}));
var app;
(function (app) {
var controllers;
(function (controllers) {
var BarController = (function () {
function BarController() {
}
return BarController;
}());
controllers.BarController = BarController;
})(controllers = app.controllers || (app.controllers = {}));
})(app || (app = {}));
I noticed that there are 2 instances of var app;
being generated. It seems like it should only be generated once. Is there a way to achieve a cleaner structure like this?
var app;
(function (app) {
var controllers;
(function (controllers) {
var FooController = (function () {
function FooController() {
}
return FooController;
}());
controllers.FooController = FooController;
var BarController = (function () {
function BarController() {
}
return BarController;
}());
controllers.BarController = BarController;
})(controllers = app.controllers || (app.controllers = {}));
})(app || (app = {}));
Is this optimization possible? If not, are there any tools available to simplify the generated javascript code to achieve the desired output? Thanks in advance!