Skip to content

Error in generated js by typescript compiler #10224

Closed
@pooyaho

Description

@pooyaho

I have a problem with type script generated js file and I can't solve it, this is my service file that I have problem with it:

namespace Providers {

    export interface IProvider {
        loadTranslations(translations: ITranslations, locale: string);
    }
    module.provider('lego', LegoProvider); 

    class LegoProvider implements ng.IServiceProvider ,IProvider{

        loadTranslations(translations:ITranslations , locale: string) {
            ......
        }

        $get() {
            .....
        }
    }

}

and generated js file is:

var Providers;
(function (Providers) {
    module.provider('lego', LegoProvider); // this is the problem
var LegoProvider = (function () {
    function LegoProvider() {
}
LegoProvider.prototype.loadTranslations = function (translations, locale) {
};
LegoProvider.prototype.$get = function () {
};
return LegoProvider;
}());
})(Providers || (Providers = {}));

It throws error because of the LegoProvider is variable and in that line it is still undefined. when I change code with this, it works correctly:

namespace Providers {

    export interface IProvider {
        loadTranslations(translations: ITranslations, locale: string);
    }


    class LegoProvider implements ng.IServiceProvider ,IProvider{

        loadTranslations(translations:ITranslations , locale: string) {
            ......
        }

        $get() {
            .....
        }
    }
    module.provider('lego', LegoProvider); // I've moved this line to bottom

}

In typescript code LegoProvider class is accessible from both positions and it doesn't make sense for me that the first position is incorrect

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions