You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
The text was updated successfully, but these errors were encountered:
Code runs in the order you write it; TypeScript doesn't re-order it on your behalf. It's possible you needed to run module.provider before class initialization (for example, because LegoProvider initialized a static field in a way that depended on the module.provider call).
@RyanCavanaugh is there any way that TS could throw an error in such cases - kind of like when you try to use variable that is declared later in the file - got bitten by it myself couple of times
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:
and generated js file is:
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:
In typescript code LegoProvider class is accessible from both positions and it doesn't make sense for me that the first position is incorrect
The text was updated successfully, but these errors were encountered: