AngularJS:TypeScript 编译过程和 gulp-uglify - 有没有办法强制 TS 使用 IIFE 生成函数而不是变量?

AngularJS: TypeScript compile process and gulp-uglify - is there a way to force TS to produce functions instead of variable with IIFE?

我有 AngularJS controller:

ArticleController.prototype = Object.create(BaseController.prototype);

/* @ngInject */

function ArticleController (CommunicationService){
    //Some code not related with problem
}

用 gulp 缩小:

return gulp.src(pathsToMinify)
        .pipe(require('gulp-ng-annotate')())
        .pipe(require('gulp-uglify')())
        .pipe(require('gulp-concat')('application.min.js'))
        .pipe(gulp.dest('dist'));

然后我决定从 Javascript 迁移到 Typescript,从 BaseController:

开始
class BaseController {
    constructor() {
        //Some code not related with problem
    }
}

缩小和连接后,我得到:

Uncaught TypeError: Cannot read property 'prototype' of undefined

相关行:

ArticleController.prototype = Object.create(BaseController.prototype);

然后我意识到 Typescript 编译器将 BaseController 作为 IIFE 变量:

var BaseController = (function () {
    function BaseController() {

    }
    BaseController.prototype.setPath = function (path) {
        this._path = path;
    };
    //Some code not related with problem
    return BaseController;
})();

问题 IMO 与 Javascript 中的 variable/function 提升有关 - 当我手动将变量和 IIFE 替换为函数时:

function BaseController() {
}
//Some code not related with problem

它工作正常。有没有办法解决这个问题,比如强制 Typescript 编译器输出函数而不是 IIFE 变量?或者,我不能改变它,我必须以其他方式处理它?预先感谢您的帮助,我是 Typescript 的新手,我没有意识到我可以找到这样的问题。

很可能,BaseControllerArticleController 中不可见(因为它是在例如之后连接的)。

为避免此类问题,请编写模块化 Typescript(es6 and/or commonjs 样式)并使用 webpack 或 browserify