Closed
Description
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